error in os.chdir

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jun 30 08:32:27 EDT 2018


On Sat, 30 Jun 2018 04:47:44 -0700, Sharan Basappa wrote:

>> The quick fix:
>> 
>> put an r in front of the directory string: r'...'
>
> thanks. That works

Please don't do that. It's the wrong solution -- all you are doing is 
postponing failure. It will *seem* to work, until one day you will write 
something like this:

    directory = r'D:\directory\'

and you will get a mysterious failure. Chris gave you the right solution: 
use forward slashes instead of backslashes for all paths.

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




-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson




More information about the Python-list mailing list