Reading CSV file from bottom using Python

1149250 pts.
Tags:
CSV file
Python
Can I read my CSV file in reverse order using Python? I figured out for a .TXT file but I'm stick with this one. Or is it really just the same method?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.
for line in reversed(open("filename").readlines()):
    print line.rstrip()

And in Python 3:

for line in reversed(list(open("filename"))):
    print(line.rstrip())

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    It all depends on what you want to do with it.

    A csv file is a text file, so, you can definitely use the same method, but if you want additional features that are only used with CSV files, then there are other ways.
    85,005 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: