open() function python default directory

后端 未结 7 1438
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 00:23

I\'m new and I have no idea where the default directory for the open() function is.

For example open(\'whereisthisdirectory.txt\',\'r\')

相关标签:
7条回答
  • 2021-01-05 01:12

    First, you must import:

    import os
    

    Then to print the current working directory:

    os.getcwd()
    

    If you want to change the current working directory:

    os.chdir('your_complete_required_path')
    
    0 讨论(0)
提交回复
热议问题