[英]Passing a parameter to main method of a class
How can I pass a parameter to __main__
method?如何将参数传递给__main__
方法?
Suppose I have the following class resides in a file base.py
:假设我有以下类驻留在文件base.py
:
class Base(object):
var_text = ""
def do_something(self):
pass
if __name__ == '__main__':
print (var_text)
Now, I have a file child.py
where I want to pass var_text
to main method in base.py
.现在,我有一个文件child.py
,我想将var_text
传递给base.py
main 方法。 How do I do that?我怎么做?
#!/usr/bin/python
def test(self):
b = Base()
Thank you in advance.先感谢您。
With inheritance you can do it as such通过继承,您可以这样做
class Base(object):
var_text = "hello"
def do_something(self):
pass
class Child(Base):
pass
child = Child()
print child.var_text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.