【发布时间】:2021-04-18 17:41:41
【问题描述】:
您好,我对 click 和 python 比较陌生,我正在尝试通过 click 将变量传递给类中的方法。我不确定点击装饰器是否应该高于 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
【问题讨论】:
标签: python-3.x class inheritance methods click