Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied error while writing to a file in Python

Tags:

python

I want to create a file and write some integer data to it in python. For example, I have a variable abc = 3 and I am trying to write it to a file (which doesn't exist and I assume python will create it on its own):

fout = open("newfile.dat", "w") fout.write(abc) 

First, will python create a newfile.dat on its own? Secondly, it's giving me this error:

IOError: [Errno 13] Permission denied: 'newfile.dat' 

What's wrong here?

like image 623
user1921843 Avatar asked Aug 30 '13 09:08

user1921843


People also ask

How do I fix error denied permissions?

Right-click the file or folder, and then click Properties. Click the Security tab. Under Group or user names, click your name to see the permissions that you have. Click Edit, click your name, select the check boxes for the permissions that you must have, and then click OK.


1 Answers

Please close the file if its still open on your computer, then try running the python code. I hope it works

like image 120
Aseem Avatar answered Sep 24 '22 07:09

Aseem