在 运行 脚本之前查找未初始化的变量
Finding uninitialized variables before running script
如何检测 Python 脚本中 运行 脚本之前的所有变量是否都已初始化?理想情况下,我希望我的编译器(目前 Wing IDE)能够在 build/compilation 过程中检测错误。这是为了防止程序在加载数据等约 30 分钟后因简单错误而崩溃。
我知道 Python 可以用各种方式操纵变量。然而,我的脚本往往相当简单,我不希望该方法是防弹的。
作为示例,我希望错误检测方法能够找到简单的错误,例如下面脚本中 grocery_bill
的拼写错误。
prices = {'apple': 0.40, 'banana': 0.50}
my_purchase = {
'apple': 1,
'banana': 6}
grocery_bill = sum(prices[fruit] * my_purchase[fruit]
for fruit in my_purchase)
print 'I owe the grocer $%.2f' % grocery_blil
如何检测 Python 脚本中 运行 脚本之前的所有变量是否都已初始化?理想情况下,我希望我的编译器(目前 Wing IDE)能够在 build/compilation 过程中检测错误。这是为了防止程序在加载数据等约 30 分钟后因简单错误而崩溃。
我知道 Python 可以用各种方式操纵变量。然而,我的脚本往往相当简单,我不希望该方法是防弹的。
作为示例,我希望错误检测方法能够找到简单的错误,例如下面脚本中 grocery_bill
的拼写错误。
prices = {'apple': 0.40, 'banana': 0.50}
my_purchase = {
'apple': 1,
'banana': 6}
grocery_bill = sum(prices[fruit] * my_purchase[fruit]
for fruit in my_purchase)
print 'I owe the grocer $%.2f' % grocery_blil