[Tutor] Newbie question.
Pijus Virketis
virketis@post.harvard.edu
Mon, 27 May 2002 01:11:33 -0400
<HTML><HEAD>
<BASEFONT FACE=3D"Arial" SIZE=3D"2" COLOR=3D"#000000">
</HEAD>
<BODY>
<div>Hi SA, <br></div>
<div> </div>
<div><FONT COLOR=3D"#000080">>I'm trying to use the os.listdir=
module to list a directory and then</FONT><br>
<FONT COLOR=3D"#000080">>store</FONT><br>
<FONT COLOR=3D"#000080">>that output to a list. I'm probably=
doing this wrong:</FONT><br>
<FONT COLOR=3D"#000080">>X =3D listdir(/)</FONT><br>
<br></div>
<div>A quick note: I assume that you have imported the os module=
with "from os import *", seeing that you don't need to=
qualify the call to listdir(). I suggest that you instead=
do:<br></div>
<div> </div>
<div>>>> import os<br></div>
<div>>>> path_list =3D os.listdir("/") # note=
the quotes!<br></div>
<div> </div>
<div>So, the problem was that the listdir() function was=
expecting a string argument, i.e. "/" rather than just=
/ that you passed to it. <br></div>
<div>As for the import issue, "from foo import *" is=
dangerous, because if you had written your own function baz(),=
and another function with the same name existed in the foo=
module, then your baz() would get clobbered in the namespace. If=
you do "import foo", then your baz() and foo.baz() do=
not interfere.<br></div>
<div> </div>
<div>Cheers, <br></div>
<div> </div>
<div>Pijus<br></div>
</body></html>