Question about importing modules

Ken Beesley ken.beesley at xrce.xerox.com
Sat Aug 21 15:14:12 EDT 2004


pythos at bag.python.org wrote:

>Newbie at python (but not programming) here...
>
>I have a program that has "import os" at the top, and then later a call to
>utime() is made.  The python interpreter says "name 'utime' is not defined".
>But if I change "utime(...)" to "os.utime(...)" then it works fine.  Perhaps I
>am expecting the "import os" statement to work the same way as "import
><package_name>.*" does in Java.  So is it the case that if I write "import os"
>in python, then I still need to write "os.utime(...)"?  Or is there something
>else wrong?  Thanks.
>
>  
>
What you want is

from os import utime

which will make 'utime' a name in the local namespace.

Ken




More information about the Python-list mailing list