468,291 Members | 1,569 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,291 developers. It's quick & easy.

IOError: [Errno 13] Permission denied: while writing to a file in windows python

I am trying to write to a file inside folder.But it is failing with below error.Please help.

Traceback (most recent call last):
File "C:/Users/admin/Desktop/scripts/de.py", line 6, in <module>
with open(mypath,"w+") as x:
IOError: [Errno 13] Permission denied: 'C:/Users/admin/Desktop/scripts25/hj214/f.txt'

Here is my code:
import os
mypath ="C:/Users/admin/Desktop/scripts25/hj214/f.txt"
if not os.path.exists(mypath):
os.makedirs(mypath,0755);
print"Path is created"
with open(mypath,"w") as x:
x.write("This is a boy")
Oct 16 '18 #1
1 6321
dwblas
626 Expert 512MB
is mypath a directory
Expand|Select|Wrap|Line Numbers
  1. os.makedirs(mypath,0755)
or a file
Expand|Select|Wrap|Line Numbers
  1. with open(mypath,"w") as x: 
it can't be both.
Oct 18 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by JaazzMan | last post: by
7 posts views Thread by Stéphane Ninin | last post: by
4 posts views Thread by zombek | last post: by
6 posts views Thread by Antoine De Groote | last post: by
reply views Thread by Robert Dollinger | last post: by
3 posts views Thread by John Machin | last post: by
reply views Thread by Simo D | last post: by
reply views Thread by Simo D | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.