[Chicago] Got it Re: opening a file for read in 3.2

Jordan Bettis jordanb at hafd.org
Thu Nov 1 03:27:28 CET 2012


On 10/31/2012 04:53 PM, Randall Baxley wrote:
> 
> Answer if you want though I got going again.  For some reason .txt did
> not get appended to the file name.
> 
> Randy

Remember that Python is written by Unix guys. There's nothing special
about file extensions on Unix, they're completely arbitrary and
optional. So python will try to open a file with exactly the name you
give it, extension or not.

Two useful tools are os.getcwd() and os.listdir(). The first returns the
path to the current working directory. The second returns a listing of
the files in a directory, as python sees them. So to get a directory
listing from python's perspective, you can do:

import os
print os.listdir(os.getcwd())




More information about the Chicago mailing list