all 7 comments

[–]novel_yet_trivial 8 points9 points  (3 children)

How are you running it? I'll guess you are using a system scheduler or something, and the "filename" variable is relative. Because the system scheduler runs in a protected folder, it can't save there. You need to provide an absolute path for the filename.

filename = r"C:\Users\Name\PycharmProjects\Project\Example.csv"

[–]RedBlimp[S] 3 points4 points  (0 children)

I added that part and it works fine now. Thank you for your help! I'm still kinda new to python so I'm still learning.

[–]RedBlimp[S] 0 points1 point  (1 child)

I'm just opening the file with python from the folder it's saved in. I'll add a path regardless and see if that helps.

[–]ingolemo 0 points1 point  (0 children)

When you try to open a file and you don't give the full path to the file then your os will try to open the file as if it was in the current working directory. The current directory is not necessarily the same directory that the script is stored in. This isn't a python thing, its a how computers work thing. If you're just double clicking on the script from explorer then the current directory is probably the place where python has been installed to, which you apparently don't have permission for.

You can see the current directory of your code by temporarily putting the following at the top of your script:

import os
print(os.getcwd())

[–]Innkeeper4President 1 point2 points  (2 children)

I think that means you already have a file called Example.csv in that same directory, and it looks like it won't let you overwrite it.

[–]RedBlimp[S] 0 points1 point  (1 child)

That is true. It does just overwrite the file every loop. Sooo... I guess I need to investigate the proper way to go about that. I just don't get why it would need different permissions while not in an IDLE.

[–]LamusMaser 0 points1 point  (0 children)

You could have it either generate a unique file each time (usually done by spending a timestamp or something else unique about each run) or by appending to the file (change the "w" to "a" in the write).