import sys
def exec_smth():
# execution without effect
exec('write_smth')
try:
# execution with exception because of missing argument
exec('write_smth()')
except TypeError as error:
# now we pass an argument
exec('write_smth("I failed because of %s" % error )')
def write_smth(smth):
sys.stdout.write(smth)
exec_smth()
您忘记向
changeDir
函数传递“name”参数。也没有例外,因为你的声明没有效果!在表示问题的代码段:
总之,在你的}s,所以你的代码无论如何都会失败!在
__init__
函数之外,由于垃圾收集器,根本没有{还有更多的问题,因为你从来没有将你的
^{pr2}$sv{}
绑定到一个小部件上,并期望得到一些回报!但是好吧,让我们试着用exec
来做一些事情:输出:
正如您所见-我们总是需要一个对StringVars的引用,我认为带有一个StringVars列表的选项要好得多!在
注意:如果需要将某些内容传递给回调函数-请使用
lambda
函数!所有代码都用python3测试过。链接:
相关问题 更多 >
编程相关推荐