open() function python default directory

后端 未结 7 1459
爱一瞬间的悲伤
爱一瞬间的悲伤 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 00:53

    The open() function for file always creates files in the current working directory. The best way to find out your current working directory is to find three lines of small code:

    import os
    current_working_directory = os.getcwd()
    print(current_working_directory)
    

    Run this above code and you will get your current working directory where open() function creates a new file. Good Luck!

提交回复
热议问题