[Tutor] listdir
Peter Brown
peterabrown at froggy.com.au
Mon Jan 12 00:17:07 EST 2004
See below
At 20:42 11/01/04 -0800, you wrote:
>I was trying to use listdir to look into the contents
>of a file on my Win2K system. According to the online
>docs, I should be able to do this, but instead, I get
>the following error message:
>
> >>> import os
> >>> listdir('C:\Documents and Settings\Christstopher
>Spears\My Documents\python')
>
>Traceback (most recent call last):
> File "<pyshell#1>", line 1, in -toplevel-
> listdir('C:\Documents and Settings\Christstopher
>Spears\My Documents\python')
>NameError: name 'listdir' is not defined
>
>What does this mean? I have the same problem when I
>try to rename a file.
>
>
>=====
>"I'm the last person to pretend that I'm a radio. I'd rather go out and
>be a color television set."
>-David Bowie
>
>"Who dares wins"
>-British military motto
>
>"Far more creativity, today, goes into the marketing of products than into
>the products themselves..."
>-"Pattern Recognition" by William Gibson
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
Chris,
You haven't fully qualified name.
if you use
>>>import os
you have to fully qualify the function
>>> a= os.listdir('e:/voip')
>>> a
['04-iad.pdf']
or use
>>>from os import listdir
>>>a=listdir('e:/voip')
>>> a
['04-iad.pdf']
If more than one file in directory naturally you get more file names in list
Peter
More information about the Tutor
mailing list