error in os.chdir

Sharan Basappa sharan.basappa at gmail.com
Sat Jun 30 07:47:44 EDT 2018


On Saturday, 30 June 2018 16:51:53 UTC+5:30, Karsten Hilbert  wrote:
> On Sat, Jun 30, 2018 at 04:05:22AM -0700, Sharan Basappa wrote:
> 
> > I need to change directory to my local working directory in windows and then open a file for processing.
> > Its just a 3 lines code, as below:
> > import csv
> > import os
> > os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion')
> > The error is as follows:
> > WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion'
> > Notice x07 character that has replaced character x07.
> > I have a similar code but that goes through fine:
> > import csv
> > import os
> > os.chdir('D:\Projects\Initiatives\machine learning\programs')
> > 
> > with open('example.csv') as csvfile:
> >     readCSV = csv.reader(csvfile, delimiter=',')
> > The only difference is directory assertion in the problematic code.
> > I have tried single quoting, double quoting etc. for the chdir directive but nothing helps. I have also tried escaping as \assertion but that is not the issue
> 
> The quick fix:
> 
> put an r in front of the directory string: r'...'
> 
> Karsten
> -- 
> GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B

thanks. That works



More information about the Python-list mailing list