error in os.chdir

Chris Angelico rosuav at gmail.com
Sat Jun 30 07:21:33 EDT 2018


On Sat, Jun 30, 2018 at 9:05 PM, Sharan Basappa
<sharan.basappa at gmail.com> wrote:
>
> 0
> down vote
> favorite
>
> 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')

Use forward slashes instead of backslashes for all paths.

os.chdir('D:/Projects/Initiatives/machine learning/programs')

ChrisA



More information about the Python-list mailing list