假设运行在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请阅读问题。 –