user2694517 user2694517 - 1 month ago 10
Python Question

Permission Error running through Notepad++

I have a Python 2.7 program that prints a set of data to a text file at the end. The program works perfectly if I import the file into the Pythonshell, but if I attempt to run the script directly from Notepad++ using Crl+R (also using Pythonshell), I get an error:

Traceback (most recent call last):
File "C:\Python27\ZeemanLab.py", line 140, in <module>
with open("Mercury{}at{}A".format(wavelength, B), "w") as f:
IOError: [Errno 13] Permission denied: 'Mercury55at55A'


The problem line:

with open("Mercury{}at{}A".format(wavelength, B), "w") as f:
f.write('A {}nm lamp in a {}A Magnetic field \n'.format(wavelength, B))


I am clueless as to what would make this difference.

Answer Source

Adding and printing the result of os.getcwd() might help you troubleshoot. Perhaps Notepad++ is running the script from a different working directory? Have you tried using an absolute path name like C:\temp\Mercury{}at{}A?