@Wayne, sorry to have replied to you directly.. On Sun, Feb 21, 2010 at 9:23 PM, Sithembewena Lloyd Dube <zebr...@gmail.com>wrote:
> Solved by moving the file just under C:\ > > Must be an issue with directory name spaces. > > By the way, my code was riddled with bugs. readlines() returns a list > object, which does not have a close method - and i had not placed quotes > around the new_file argument. > > > > > On Sun, Feb 21, 2010 at 9:01 PM, Sithembewena Lloyd Dube < > zebr...@gmail.com> wrote: > >> Hi Wayne, >> >> Thank you for responding. I did try declaring it as a raw string, and what >> i get is pretty much the same result (slashes in the path become double >> slashes, so naturally the file is not found). >> >> I did try googling around for how to handle/ escape file paths, but i >> cannot seem to dig up anything useful. >> >> Regards, >> Sithembewena >> >> >> On Sun, Feb 21, 2010 at 8:41 PM, Wayne Werner <waynejwer...@gmail.com>wrote: >> >>> On Sun, Feb 21, 2010 at 12:22 PM, Sithembewena Lloyd Dube < >>> zebr...@gmail.com> wrote: >>> >>>> Hi all, >>>> >>>> I'm trying to read a file (Python 2.5.2, Windows XP) as follows: >>>> >>>> assignment_file = open('C:\Documents and Settings\coderoid\My >>>> Documents\Downloads\code_sample.txt', 'r+').readlines() >>>> new_file = open(new_file.txt, 'w+') >>>> for line in assignment_file: >>>> new_file.write(line) >>>> >>>> new_file.close() >>>> assignment_file.close() >>>> >>>> When the code runs, the file path has the slashes converted to double >>>> slashes. When try to escape them, i just seemto add more slashes. What am >>>> i >>>> missing? >>> >>> >>> try using the r to declare it as a raw string: >>> >>> filename = r'C:\Documents and Settings\coderoid\otherstuff' >>> >>> filename >>> 'C:\\Documents and Settings\\coderoid\\otherstuff' >>> >>> that should work. >>> >>> HTH, >>> Wayne >>> >>> >>> -- >>> To be considered stupid and to be told so is more painful than being >>> called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every >>> weakness, every vice, has found its defenders, its rhetoric, its ennoblement >>> and exaltation, but stupidity hasn’t. - Primo Levi >>> >> >> >> >> -- >> Regards, >> Sithembewena Lloyd Dube >> http://www.lloyddube.com >> > > > > -- > Regards, > Sithembewena Lloyd Dube > http://www.lloyddube.com > -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.com
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor