directory listing
Shi Mu
samrobertsmith at gmail.com
Fri Nov 11 17:44:22 EST 2005
On 11/11/05, Fredrik Lundh <fredrik at pythonware.com> wrote:
> Shi Mu wrote:
>
> > I tried this and no error reported but nothing appear on the console, why?
> >
> > import os
> >
> > def buildList( directory='c:\TEMP' ):
> > dirs = [ ]
> > listing = os.listdir(directory)
> > for x in listing:
> > x = os.path.join(directory, x)
> > print x
> > if os.path.isdir(x):
> > dirs.append(x)
> > return dirs
>
> is that the entire script? you're defining a function, but you're
> not calling it. try adding
>
> print buildList()
>
> at the end of the script.
It works but i am curious why the line of "print x" does not show
anything. many thanks!
More information about the Python-list
mailing list