Easy question on opening a file

Jeremy Bowers jerf at jerf.org
Tue Sep 14 00:03:26 EDT 2004


On Mon, 13 Sep 2004 20:57:35 -0700, news.west.cox.net wrote:
> files = os.listdir('/direcory')
> if len(files) > 0:
>     for file in files:
>         f1 = file(file, "r")
>         do some other stuff

This will help you:

files = os.listdir('/directory')
print "The name 'file' is bound to:", repr(file)
for file in files:
	print "Now the name 'file' is bound to:", repr(file)

(Probably one of the last little warts I get bitten by often is that the
builtins are named a little *too* conveniently... :-) OK, even "wart" is
strong, but you know what I mean.)



More information about the Python-list mailing list