Python Sheepsheet: Opening and reading a text file.

Next on the list of simple stuff not to forget: Opening and reading a text file.

Matasano Set 1, Challenge 4 includes a text file to read from. The most Pythonic way to read the list from the text file I have found was excellently simple:

f = open( “filepath” )
filedata = list( f )
f.close()

Wow, was that easy. I gotta remember that one. Oh right, I’ll write about it.

Advertisements

About Steve

I am. Growing Learning Living
This entry was posted in sheepsheet and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s