What exactly is Current working directory?

后端 未结 4 911
一整个雨季
一整个雨季 2021-01-20 16:10

My book states:

Every program that runs on your computer has a current working directory, or cwd. Any filenames or paths that do not begin with the r

4条回答
  •  借酒劲吻你
    2021-01-20 16:43

    Your python interpreter location is based off of how you launched it, as well as subsequent actions taken after launching it like use of the os module to navigate your file system. Merely starting the interpreter will place you in the directory of your python installation (not the same on different operating systems). On the other hand, if you start by editing or running a file within a specific directory, your location will be the folder of the file you were editing. If you need to run the interpreter in a certain directory and you are using idle for example, it is easiest to start by creating a python file there one way or another and when you edit it you can start a shell with Run > Python Shell which will already be in that directory. If you are using the command line interpreter, navigate to the folder where you want to run your interpreter before running the python/python3/py command. If you need to navigate manually, you can of course use the following which has already been mentioned:

    import os
    os.chdir('full_path_to_your_directory')
    

提交回复
热议问题