开发者

os.chdir(path) not working as expected due to path formatting in Python 2.6.5?

开发者 https://www.devze.com 2023-01-05 13:36 出处:网络
I cannot os.chdir(path) in Python 2.6.5 und开发者_如何学Cer WindowsXP SP2. It works fine under CygWin and MAC OS X, but for WinXP regardless of path format, I always get this error:

I cannot os.chdir(path) in Python 2.6.5 und开发者_如何学Cer WindowsXP SP2. It works fine under CygWin and MAC OS X, but for WinXP regardless of path format, I always get this error:

AttributeError: 'str' object has no attribute 'chdir'.

I thought it was the problem with format of path but after trying r"C:\WINDOWS", 'C:\WINDOWS' and combinations of \\, / or even "\"C:\Windows\"", I gave up. With formatting I'm using os.path.exists(path) works perfectly fine...

What I am missing here? What should I be aware of when working with paths consisting of white spaces?

Cheers, Martin


It seems that problem is that in some place you redefine 'os'. Somewhere in your code you do something like this:

import os
os = 'some string'
0

精彩评论

暂无评论...
验证码 换一张
取 消