Appending to a file in Python
I have been getting an error : 'file' object has no attribute 'append' I am trying to append a new user on my .htaccess file and once I figure this part I think the rest of my code will work perfectly. This is a snippet of where the error is coming from: Basically if the dirpath exists I want a new required user appended to the list. I am still new to python so if something looks really wacky - sorry. ;) def createUser(username, basedir): import os dirpath = "/var/www/html/da/" + basedir + "/.htaccess" if os.path.isfile(dirpath): filename=open(dirpath, 'a') filename.append('Require user ' + username + '\n') Thanks
On Thu, May 20, 2004 at 11:36:36AM -0500, Laura McCord wrote:
I have been getting an error : 'file' object has no attribute 'append'
That's because python file objects really do not have an append method :-) Try the write method instead. It's good to get familiar with the Python docs, particularly the standard library reference: http://docs.python.org/lib/lib.html In this case, under "built-in types", you will find this: http://docs.python.org/lib/bltin-file-objects.html -- Paul Winkler http://www.slinkp.com
participants (2)
-
Laura McCord -
Paul Winkler