【发布时间】:2018-10-29 15:10:18
【问题描述】:
当我在函数中定义一个使用函数参数的类时,抛出 NameError: name 'x' is not defined。
def foo(x):
class Meta:
x = x
foo(1)
# throw NameError
NameError: name 'x' is not defined
【问题讨论】:
标签: python
当我在函数中定义一个使用函数参数的类时,抛出 NameError: name 'x' is not defined。
def foo(x):
class Meta:
x = x
foo(1)
# throw NameError
NameError: name 'x' is not defined
【问题讨论】:
标签: python
您在类中的字段x 正在从函数中屏蔽参数x。
def foo(x):
class Meta:
y = x
foo(1)
将停止给你这个错误。
这个问题写得不好(甚至没有一个问题),所以我可能误解了你。
【讨论】: