What's the working directory when using IDLE?

前端 未结 4 428
无人共我
无人共我 2020-12-08 01:13

So, I\'m learning Python and would like to create a simple script to download a file from the internet and then write it to a file. However, I am using IDLE and have no idea

4条回答
  •  有刺的猬
    2020-12-08 01:20

    You can check that using os.getcwd():

    In [1]: import os
    
    In [2]: os.getcwd()
    Out[2]: '/home/monty'
    
    In [7]: os.chdir("codechef")    #change current working directory
    
    In [8]: os.getcwd()
    Out[8]: '/home/monty/codechef'
    

    os.chdir():

    In [4]: os.chdir?
    Type:       builtin_function_or_method
    String Form:
    Docstring:
    chdir(path)
    

    os.getcwd():

    Change the current working directory to the specified path.
    
    In [5]: os.getcwd?
    Type:       builtin_function_or_method
    String Form:
    Docstring:
    getcwd() -> path
    
    Return a string representing the current working directory.
    

提交回复
热议问题