-1
使用變量:從我有這個問題的一些其他Python文件
我有兩個文件:隨機random2
隨機有這樣的:
import random2
print(random2.verb_list)
print(random2.x)
random2有這樣的:
verb_list = ['x', 'y', 'z']
other_list = ['1', '2', '3']
something_else = False
def Main():
global x
x = 1
print(verb_list)
if __name__ == "__main__":
Main()
當我隨機運行時,它給了我這個錯誤:
AttributeError: module 'random2' has no attribute 'x'
有沒有辦法讓我可以隨意調用變量x? 我有python3
嘗試在你的函數外實際聲明'x' –
[python使用另一個文件中的變量]可能的重複(http://stackoverflow.com/questions/14573021/python-using-variables-from-another-file) –
@WayneWerner我已經嘗試過,它的工作原理。但我想要做的是更改函數中的x值。可能嗎? – luistripa