IPython 如何处理局部变量?我有这个函数可以在 Python shell 中工作,但不能在 IPython shell 中工作。
def change(key,value):
global aname
global alist
alist.append(key)
aname.extend(value)
我在一个for
循环中使用它,它从 JSON 和其他 .txt 文件中读取输入,并将键和值添加到列表中,然后另一个函数使用该列表保存到数据库中。如果我不这样做,它会很丑陋,并且会在我的循环中使用索引。
[change(key,value) for key,value in jsondata.itervalues()]
def storeindatabase():
do_sothing to the list aname and store
do_sothing to the alist and store