OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

error in os.chdir


On Saturday, 30 June 2018 18:05:02 UTC+5:30, Steven D'Aprano  wrote:
> 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

alright. I will do that but still I don't have an answer why I got the error in the first place.