Python-crontab包返回__init__错误

 Fier田野莎莎 发布于 2023-02-13 17:19

任何人都可以告诉我我用python-crontab做错了什么?

from crontab import CronTab
system_cron = CronTab()

生成以下错误:

File "test.py", line 3, in 
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=[>, >, >, , >, , >, >, >, >, >], 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

Lie Ryan.. 10

你已经安装了crontab包,你展示的文档是python-crontab.他们是两个完全不同的包.

1 个回答
  • 你已经安装了crontab包,你展示的文档是python-crontab.他们是两个完全不同的包.

    2023-02-13 17:20 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有