我有一個函數:寫入控制檯或文件蟒蛇
def hello_world(output):
output.write("Hello World")
,並希望這些傳遞給它:
file = io.open("myfile.txt", "w")
hello_world(file)
hello_world(sys.stdout)
我不知道這是否是正確的這樣。我也得到NameError: global name 'sys' is not defined
你會怎麼做我想做的?