Kesong Xie Kesong Xie - 1 year ago 117
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download