423,851 Members | 2,762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,851 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/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
Share this Question
Share on Google+
1 Reply


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