Can't create, open, write files in python

Question:

f = open("demofile3.txt", "w")
f.writelines(["nSee you soon!", "nOver and out."])
f.close()

`

I have been trying to create or open a file and write something in it but it does not seem to do anything.

Asked By: Luka Murghulia

||

Answers:

it’s about pwd.

But here is a method: use full path.

For example:

from pathlib import Path
folder = Path(__file__).parent
your_txt = folder / "demofile3.txt"
with open(your_txt, "w") as f:
    f.writelines(["nSee you soon!", "nOver and out."])
Answered By: AsukaMinato
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.