2013-03-14 83 views

回答

5

東西已經是可怕的錯誤。

# This is a horrible monstrosity, but it does what you ask 
name = raw_input('name> ') 
globals()[name] = [1, 2, 3] 

您應該使用正確的字典來代替。

x = { } 
name = raw_input('name> ') 
x[name] = [1, 2, 3] 

列表實際上並沒有名稱。

x = [1, 2, 3] 

[1, 2, 3]是什麼名字?錯誤的問題是,它沒有名稱,只有一個值(和內存中的位置)。只有變量有名字。

+0

哇,謝謝。巨大的幫助。 – 2013-03-14 11:41:52

相關問題