2013-12-08 59 views
0

當tring改變目錄時,我總是收到以下錯誤:任何人都可以幫助解決問題以及如何解決這個問題?更改目錄時輸入錯誤

代碼片段: -

print "changing dir..." 
print "BUILDDIR: " + BuildDir 
os.chdir(BuildDir) 
print "Done changing dir..." 

錯誤: -

changing dir... 
BUILDDIR: /local/mnt/workspace/username/AU_LINUX_ANDROID_CHO_3.5.04.03.00.003.047_msm8216/ 
Traceback (most recent call last): 
    File "Main.py", line 682, in <module> 
    flist = fd.readlines() 
    File "Main.py", line 654, in main 
    picked_gerrits = [] 
    File "Main.py", line 126, in RepoSync 

TypeError: must be encoded string without NULL bytes, not str 
+0

可能重複:http://stackoverflow.com/questions/12591575/python-typeerror-must-be-encoded-string-without -null-bytes-not-str – sPaz

+0

@spaz - 我看着它..am使用前斜槓「/」,你從錯誤鏡頭看到.. – user2955256

回答

0

很難說沒有能夠再現。嘗試:

'/'.join(map(str.strip, BuildDir.split('/'))) 

如果不是這是google brought me

import os, re 

_split = re.compile(r'[\0%s]' % re.escape(''.join(
    [os.path.sep, os.path.altsep or '']))) 

def secure_filename(path): 
    return _split.sub('', path) 

print '/%s/' % '/'.join([secure_filename(x) for x in BuildDir.split('/') if x]) 
+0

不清楚你在暗示什麼....需要什麼在做os.chdir(BuildDir) – user2955256

+0

之前做過BuildDir變量對不起,回答更新 –

+0

不幸的是,兩者都沒有工作......只是想知道是否有一個簡單的r的方式.. – user2955256