[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>&nbsp;</div>
<div><FONT COLOR=3D"#000080">&gt;I'm trying to use the os.listdir=
 module to list a directory and then</FONT><br>
<FONT COLOR=3D"#000080">&gt;store</FONT><br>
<FONT COLOR=3D"#000080">&gt;that output to a list. I'm probably=
 doing this wrong:</FONT><br>
<FONT COLOR=3D"#000080">&gt;X =3D listdir(/)</FONT><br>
<br></div>
<div>A quick note: I assume that you have imported the os module=
 with &quot;from os import *&quot;, seeing that you don't need to=
 qualify the call to listdir(). I suggest that you instead=
 do:<br></div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; import os<br></div>
<div>&gt;&gt;&gt; path_list =3D os.listdir(&quot;/&quot;) # note=
 the quotes!<br></div>
<div>&nbsp;</div>
<div>So, the problem was that the listdir() function was=
 expecting a string argument, i.e. &quot;/&quot; rather than just=
 / that you passed to it. <br></div>
<div>As for the import issue, &quot;from foo import *&quot; 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 &quot;import foo&quot;, then your baz() and foo.baz() do=
 not interfere.<br></div>
<div>&nbsp;</div>
<div>Cheers, <br></div>
<div>&nbsp;</div>
<div>Pijus<br></div>
</body></html>