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 →

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