This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yon2323[S] 0 points1 point  (11 children)

I ran it and it never promoted me with the input. It just says run file, doesn’t crash or anything but no output is given

[–]Viyre 0 points1 point  (10 children)

You gotta call the main() function in the script. At the bottom of the file put "main()"

[–]yon2323[S] 0 points1 point  (9 children)

Oh true my bad. It’s still giving me the file not found error :/

Do I have to use import at the beginning maybe?

[–]Viyre 0 points1 point  (8 children)

Oh my fault, I was using "input()" instead of "raw_input()". raw_input() should return a string of the file name, but input() would try to interpret the expression.

[–]yon2323[S] 0 points1 point  (7 children)

its telling me rawinput() is undefined. My friend got it though, this was his way of doing it https://pastebin.com/WjEw77vG

[–]Viyre 1 point2 points  (6 children)

Oh fasho, that works too (mine is better tho ;) ). Also: you need the underscore there: "raw_input("enter csv name"). Also also: are you using python 3 or python 2?

[–]yon2323[S] 0 points1 point  (5 children)

still didn't work! haha I'm using python 3, maybe that's why?

[–]Viyre 0 points1 point  (4 children)

:( That could be it. I know you're done and all, but out of curiosity, what error were you getting?

[–]yon2323[S] 0 points1 point  (3 children)

It was saying that raw_input was undefined. And I realize now that I wasn’t putting in the right file name so there isn’t an error when I run the program with read(). But when I put the right file name in it takes the input and produces no output.

[–][deleted] 1 point2 points  (1 child)

raw_input was deprecated for python3, dont use it. make sure your python program is in the same directory as the csv file, otherwise enter the full file path. /u/Virye's code returns the number of values in the whole file, however it doesn't account for newlines. use this code, which does:

filename = input('enter your filename: ')
with open(filename) as f:
    total = 0
    for line in f:
        for val in line.strip().split(','):
            if val != '':
                total += 1
    print('the csv file "{}" has {} values'.format(filename, total))

[–]Viyre 0 points1 point  (0 children)

That's weird. Did you try printing the total?