open() function python default directory

后端 未结 7 1436
爱一瞬间的悲伤
爱一瞬间的悲伤 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')
    

提交回复
热议问题