How to know/change current directory in Python shell?

后端 未结 7 1993
无人及你
无人及你 2020-11-27 09:27

I am using Python 3.2 on Windows 7. When I open the Python shell, how can I know what the current directory is and how can I change it to another directory where my modules

7条回答
  •  失恋的感觉
    2020-11-27 10:02

    The easiest way to change the current working directory in python is using the 'os' package. Below there is an example for windows computer:

    # Import the os package
    import os
    
    # Confirm the current working directory 
    os.getcwd()
    
    # Use '\\' while changing the directory 
    os.chdir("C:\\user\\foldername")
    

提交回复
热议问题