嗨,我想从python中的另一个文件导入一个类,一切正常,但是我想导入的类收到一个命令行参数。导入(成功)后,如何在类中提供该命令行参数?(旁白:注是这是超类还是什么?idk(这意味着什么)
#class I'm importing
class trend:
def __init__(self):
self.user_name = sys.argv[1] #receives commandline argument
_______________________________________________________________
#class I want to use it in
class game:
def __init__(self):
self.twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
def do_something(self):
import filenameforthetrendclass as TC
game = TC.trend() #how do I bring in the commandline argument in here?
在顶层以外的任何地方使用
sys.argv
是个坏主意(main
,如果你有)。你应该把这件事告诉我。你知道吗首先,重写
Trend
,将user_name
作为其构造函数的参数。你知道吗仅使用
Trend
的快速示例:现在整合整个概念:
注意事项:
game
的类,然后使用game
作为局部变量。你知道吗相关问题 更多 >
编程相关推荐