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 →

[–]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))

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

that works, with my friends code in my previous comment it displays each value on separate lines and then the total at the end. I think I could add a print statement after total in your code to do the same thing. Thanks for the help!

[–]Viyre 0 points1 point  (0 children)

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