error in os.chdir
Terry Reedy
tjreedy at udel.edu
Sat Jun 30 19:51:44 EDT 2018
On 6/30/2018 7:36 PM, eryk sun wrote:
> On Sat, Jun 30, 2018 at 11:21 AM, Chris Angelico <rosuav at gmail.com> wrote:
>> 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')
>
> Only use forward slashes for legacy DOS paths passed to Windows API
> functions. Do not use forward slashes for paths in command line
> arguments, \\?\ prefixed paths, or registry paths.
To the best of my memeory, forward slashes work in arguments.
They do not work in paths to an executable.
F:\>cd dev/3x works
f:\dev\3x> ../pull prints
'..' is not recognized as an internal or external command,
operable program or batch file.
because /pull is seen as an option switch. ..\pull does (because
..\pull.bat exists).
--
Terry Jan Reedy
More information about the Python-list
mailing list