By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,584 Members | 3,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,584 IT Pros & Developers. It's quick & easy.

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

P: 1
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/", 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):
print"Path is created"
with open(mypath,"w") as x:
x.write("This is a boy")
Oct 16 '18 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 621
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.