python - 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,但无法获得正确的格式。任何帮助表示赞赏。
解决方案
推荐阅读
- node.js - 'findOneAndUpdate()' 不会更新 mongo db 中的现有数据
- scheme - 在 Scheme 中递归拆分列表
- javascript - 切换两个 Div,仅使用 Javascript。没有jQuery
- javascript - 使用 CDN 的 Web 模态抽屉示例的材料组件
- c++ - 编译时间检查 #pragma pack 的使用情况
- google-sheets - 如果相应的行范围中存在值,则计算列范围中的项目
- python - 汇总熊猫数据框中的值
- python - 获取 CUDA_HOME 环境路径 PYTORCH
- python - numpy - einsum 表示法:矩阵堆栈与向量堆栈的点积
- html - 为什么我的下拉按钮菜单和背景图像不起作用