0

As the tittle implies, i am having trouble writing to a certain file, even though I have permissions to do so. I'm not getting an error; It's like the lines of code are just being ignored. They're not doing anything.

f = open("C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/startupfile.py", 'w')

f.write("Stuff I want to write")

f.close()

Can anyone help me? Again, there's no error message. The lines are just being flat-out ignored. And yes, I am running it with permissions through the console. Is the problem that it's in the windows directory? Or am I just missing something painfully obvious here?

EDIT: Thanks for the help everyone, but it turns out that the problem was just Windows being incompetent. I found that the files appeared after a restart, which works anyway because I'm writing in the Startup folder.

  • Have you tried writing in other dir? – Alderven Jul 01 '20 at 05:18
  • Can you edit that file in notepad? – DYZ Jul 01 '20 at 05:19
  • 1
    If the above lines that you posted are the *whole* of your program, then do you still get the error? Also, if you put in a `print` statement into your full program, are those lines actually being executed? – alani Jul 01 '20 at 05:34

1 Answers1

1

I don't have enough reputation to make a simple comment, so don't interpret this as a solution to your problem, but did you try opening the file in the "wt" mode instead of only "w"? "w" mode opens the file in binary as seen here, so the issue could be that the program doesn't understand what you are trying to say because you want to edit it in the text mode. Again, I'm not sure if this is right and I'm a newbie myself, so don't interpret this as a solution, more like a commentary.

雷笑东
  • 49
  • 1
  • 10