Reading directory
Mark McEahern
marklists at mceahern.com
Wed Oct 16 14:56:44 EDT 2002
[Ilya Shambat]
> I am sorry for the naive quality of this question, but I am new to
> Python. I need to browse through a directory and read files,
> separating directory path from file name. Does anyone know the
> commands as to how to do that?
Look up the os module; e.g.,
os.listdir
os.path.basename
os.path.dirname
os.path.join
Etc.
As for reading files:
f = file("/foo/bar.txt")
for line in f:
dostuff(line)
// m
-
More information about the Python-list
mailing list