[英]An object instantiated outside of a function. How can I access from the fuction?
Tried to access as argument of the function.试图作为函数的参数访问。 Not working!不工作!
object = class()
def foo(object):
object.method
foo()
Not working!不工作!
I am going to be referring to object
as obj
since you should not be overriding built-in classes, especially since its a new-style class.我将把object
称为obj
因为您不应该覆盖内置类,特别是因为它是一个新型类。
Simply put, obj
within the function definition is a parameter name, not the variable obj
you have assigned.简单地说,函数定义中的obj
是一个参数名称,而不是您分配的变量obj
。
Therefore, when calling the function foo
, you need to provide it the parameter it asks for.因此,在调用函数foo
,您需要为其提供所需的参数。 So your code should be like this:所以你的代码应该是这样的:
foo(obj)
not foo()
不是foo()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.