假設運行在script_mode代碼塊,併產生這樣的數據:在interactive_mode和script_mode之間交換數據?
my_data = [1, 2, 3, 4] #please note this is output after running not data in script
現在我切換在控制檯工作爲調試代碼。 我需要使用剛剛生成的數據,而不能直接複製,以避免亂碼的影響。 我的解決辦法是先醃在script_mode和unpickle它interactive_mode:5個命令
代碼:
腳本模式
import pickle
with open('my_data','wb') as file:
pickle.dump(my_data, file)
Interactive_mode:
import os, pickle
# change to the working directory
os.chdir('~\..\')
with open('my_data', 'rb') as file:
my_data = pickle.load(file)
# my_data is finally loaded in console
# then manipulate it on the console.
怎麼辦它在更少的步驟?
通過互動,你的意思是IDLE?該變量是可用的 - 我剛剛檢查。 – aaron
它是一個scoped變量嗎?顯示相關的代碼。 – aaron
我使用macOS的終端和原子編輯器。@ aaron請閱讀問題。 –