首页 > 解决方案 > Python 上的函数

问题描述

我希望对如何在 Python 上使用函数有所了解。我有一个不太好的脚本工作版本,所以我尝试定义这个函数,我将在不同的文件上使用:

def controlfiles():
    domain = f'domain'
    if os.path.exists(domain):
        with open(domain, 'r') as df:
            domainoutput = df.readline()
    else:
            print("Could not load domain control file")
            exit()

等等,等等。我打开了几个文件,最后我使用:

values = [domainoutput, serveroutput, fflavoroutput, toflavoroutput, whooutput, date]
worksheet.append_row(values)

但我得到:

values = [domainoutput, serveroutput, fflavoroutput, toflavoroutput, whooutput, date]
NameError: name 'domainoutput' is not defined

我是 Python 的初学者,但我读到 open(file) 比 file=open() 好

除此之外,我还试图在 RF3339 中获取服务器时间 + 7 天来设置 Google 日历事件,到目前为止,我有:

rtime = datetime.datetime.utcnow()
rtformatted = rtime.isoformat("T") + "Z"

这适用于当前时间,但不适用于未来 7 天。我尝试了 deltatime,但无法获得正确的格式。任何帮助表示赞赏。

标签: pythonfunctionos.path

解决方案


推荐阅读