On Fri, Mar 18, 2011 at 4:59 PM, Jack Trades <jacktradespub...@gmail.com>wrote:
> > > On Fri, Mar 18, 2011 at 4:56 PM, Jon Herman <jfc.her...@gmail.com> wrote: > >> Jack, >> >> thanks. >> >> Alright, so what I did is create a file called hello.txt with a single >> line of text in there. I then did the following: >> >> f="fulldirectory\hello.txt" (where fulldirectory is of course the actual >> full directory on my computer) >> open("f", "w") >> >> And I get the following error: IOError: [Errno 13] Permission denied: 'f' >> If I open to read, I get: IOError: [Errno 2] No such file or directory: >> 'f' >> >> Can anyone explain to me why this happens? >> >> > You need to remove the quotes from f. f is a variable name, not a string, > so there should be no quotes around it. > > > -- > Jack Trades > Pointless Programming Blog <http://pointlessprogramming.wordpress.com> > > Sorry I should have given an example. From your code it should look like this... filename = "fulldirectory\hello.txt" You then use f to write or read. This is how you read... f = open(filename, "r") file_contents = f.read() f.close() and this is how you write... f = open(filename, "w") f.write("hello world") f.close() -- Jack Trades Pointless Programming Blog <http://pointlessprogramming.wordpress.com>
-- http://mail.python.org/mailman/listinfo/python-list