Kesong Xie Kesong Xie - 3 months ago 29
Python Question

failed to create new file in pycharm using open

I tried to create a empty file using

in pycharm, and it failed to create one without complaining anything

In Pycharm

fw = open("sample.txt", "w")
fw.write("what's up")

I used the same code in terminal, and it successfully created the sample.txt file.

Do I have to do some configuration in Pycharm in order to make it work?


I guess it is because you are using a relative path in fw = open("sample.txt", "w")

Try putting an absolute path like fw = open("/path/to/sample.txt", "w").

I am saying "I guess" because the error description and the stack trace are the clues to find the problem, so you should check them and always provide them when asking for help.