Ask coding questions

← Back to all posts
Cannot write to file
DavidLui (1)

Hi, I'm making a findbyname command, and I want it to automatically ask for a custom password (not a real admin password). I need the password to go to another file, so I used a with statement to do that. It works find on, but when I run the code locally, it won't work. Attached is a screenshot of my local code. Any suggestions?

MuffinsTheCat (18)

When you're done with a file, always write f.close() at the bottom. Like this:

f = open("file.txt", "w")

Python will then make a .txt file named file with the word content inside.

DavidLui (1)

It doesn't work either, I have no idea why though... @MuffinsTheCat