I want to create a file and open it and write on it with f= open('out.txt', 'a')

then it got error:
File "m.py", line 10, in <module>
f=open('./out.txt', 'a')
IOError: [Errno 13] Permission denied: './out.txt'

What happened??


I am using opensuse and was using a user account to edit and run the m.py file
python2.6.4 version

from BeautifulSoup import BeautifulSoup
import re
import urllib2

file = urllib2.urlopen("http://www.tripadvisor.com/ShowUserReviews-g294217-d305813-r49043831-Langham_Place_Hong_Kong-Hong_Kong_Hong_Kong_Region.html#REVIEWS")

soup = BeautifulSoup(file)
tag=soup.findAll(id=re.compile("^review"))

f=open('out.txt', 'a')


str = tag[1].contents
f.write(str)

Edited 7 Years Ago by gunbuster363: n/a

What platform is this? Windows XP, Ubuntu Linux, Mac OSX, etc?

There's a number of possibilities here. Most likely the folder you're working in doesn't give you write permissions.

I use opensuse

Ok, so it's most likely that the folder you're trying to open the file in doesn't have write permissions for the user that is running the python script. You could either run the script as root or simply write the file to your home directory with ~/ instead of ./

how can I change the permission setting?
I have the root account password.
I tried your method, now I can write in home directory, but not others.

how can I change the permission setting?
I have the root account password.
I tried your method, now I can write in home directory, but not others.

You would use chmod with the target being the directory

That or simply login as root before executing the script.

Oh!
I found out that the creator of the folder is root!!
because I was using root account that time, so user of course cannot modify it.....silly me

This article has been dead for over six months. Start a new discussion instead.