簡體   English   中英

獲取unicode輸入,需要將其作為字符串

[英]Getting a unicode input, need it to be a string

因此,我終於開始今天寫我的第一個程序,除了一件事之外,其他所有東西都運行順利。

在下面的代碼中,我讓用戶傳遞目錄的路徑。 我原以為這是一個字符串,但是遇到錯誤后,我設法找到了源。 問題出在哪里?我正在獲取unicode,當它用於獲取目錄中文件的列表時,這似乎會導致錯誤。

print "Hello Welcome to my little Porgram"
print "I need a little information to rename the files"
usd=getuserin("What is the file path to the files that you wish to rename?")
print "Thank you for chosing a directory path"
print "The directory path you chose was:" + " " + usd
mainname=getuserin("What is the name of the TVshow/Anime/Other thing? ")
print "Okay so its called" + " " + mainname
print "Okay I'll start renaming right away"
renamefiles(usd, mainname)

第三行是返回Unicode的那一行,基本上它所做的全部就是通過raw_input()獲取輸入。 輸入的目錄如下:

def renamefiles(directory, Mainname) :
    os.chdir(directory)
    files=os.listdir
    for elem in files:

現在,我可能會誤解該錯誤的含義,因為這基本上是我第一次編程任何東西,但我發現了正確的錯誤。

TypeError: 'builtin_function_or_method' object is not iterable

任何幫助都非常感謝

我不知道您為什么認為這與Unicode或字符串有關。 錯誤消息非常清楚:您正在嘗試遍歷實際的函數對象,而不是遍歷函數的結果。 這是因為您實際上沒有調用 os.listdir :您只是將files設置為函數本身。 要調用函數,請始終使用括號:

files = os.listdir()

將來,還請包括您得到的任何回溯。 這對於調試至關重要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM