我试图通过单击将变量传递给类中的方法。我不确定单击装饰器是否应该位于 init 之上或方法本身之上。
import click
import os
from datetime import datetime
class table_update:
scriptdirectory = os.path.dirname(os.path.realpath(__file__))
@click.command()
@click.option('-tn','--tablename',prompt=True)
def __init__(self,*args,**kwargs):
self.tablename = self.tablename
# @click.group()
# @click.command()
# @click.option('--tn','--tablename',prompt=True)
def gettime(self,tablename):
"""
Set up timer and time functions for table update
"""
print('get_time function running')
print(f"Class variable ScriptDirectoryname inherited:{self.scriptdirectory}")
print(f"here's the table: {tablename}")
global_start = datetime.now()
# get project path name & set to current path
changedir= os.chdir(self.scriptdirectory)
print(changedir)
time = table_update().gettime()
time
让我们从这个开始...
您需要写:
def __init__(self, tablename):
self.tablename = tablename
将装饰器放在方法而不是构造函数上...
老实说,我很难理解这段代码的目的是什么?你想让它做什么? 如果你解释更多我可以帮忙:)