Python-crontab包返回__init__错误

问题描述 投票:5回答:2

谁能告诉我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

对我在做什么错有任何想法吗?

help(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
python crontab
2个回答
11
投票

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


0
投票

如果出现错误TypeError:init

© www.soinside.com 2019 - 2024. All rights reserved.