gpt4 book ai didi

Python-crontab 包返回 __init__ 错误

转载 作者:太空狗 更新时间:2023-10-30 00:40:55 27 4
gpt4 key购买 nike

谁能告诉我我在使用 python-crontab 时做错了什么?

from crontab import CronTab
system_cron = CronTab()

生成以下错误:

File "test.py", line 3, in <module>
cron = CronTab()
TypeError: __init__() takes exactly 2 arguments (1 given)

当我尝试直接从包说明中获取示例的其他变体时,我遇到了同样的问题:

my_user_cron  = CronTab(user=True)
users_cron = CronTab(user='username')

我也尝试过使用这种方法创建对象,我在 python-crontab.py 文件中找到了这种方法:

cron = CronTab(tab='')

但它会生成此错误:TypeError: __init__() got an unexpected keyword argument 'tab'

我已经尝试查看包中的代码以查看是否可能是文档错误并想方设法解决问题,但这超出了我的技能水平。我相信这是定义我应该如何创建 crontab 对象的代码:

def __init__(self, user=None, tab=None, tabfile=None, log=None):
if user == True and not WINOS:
user = pwd.getpwuid( os.getuid() )[ 0 ]
self.lines = None
self.crons = None
self.filen = None
# Protect windows users
self.root = not WINOS and os.getuid() == 0
self.user = user
# Detect older unixes and help them out.
self.intab = tab
self.read(tabfile)
self._log = log

对我做错了什么有什么想法吗?

帮助(CronTab)返回:

class CronTab(__builtin__.object)
| Methods defined here:
|
| __init__(self, crontab)
|
| next(self, now=None, increments=[<function <lambda>>, <function <lambda>>, <function <lambda>>, <function _month_incr>, <function <lambda>>, <function _year_incr>, <function <lambda>>, <function <lambda>>, <function <lambda>>, <function <lambda>>, <function <lambda>>], delta=True)
| How long to wait in seconds before this crontab entry can next be
| executed.
|
| previous(self, now=None, delta=True)
|
| test(self, entry)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| matchers

最佳答案

您已经安装了 crontab包,您显示的文档适用于 python-crontab .它们是两个完全不同的包。

关于Python-crontab 包返回 __init__ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20302647/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com