Search code examples
pythonpython-importgetcwd

Python module import not working


I am getting an error with the following code:

from os import getcwd
os.getcwd()

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
os.getcwd()
NameError: name 'os' is not defined

Anyone know why importing this way is not working?


Solution

  • from os import getcwd
    print getcwd()
    

    When you have only imported getcwd and not os how can this work os.getcwd