V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
intohole
V2EX  ›  Python

一个不到 100 行的 Python crontab 实现;

  •  1
     
  •   intohole · 2017-04-01 15:42:20 +08:00 · 3254 次点击
    这是一个创建于 2580 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://github.com/intohole/pyct

    主要是大家可以看看思路,我写这个用了很短时间,如果有什么需求可以提给我

    第 1 条附言  ·  2017-04-01 17:06:27 +08:00
    这个写错了标题, 有人知道怎么删除吗?
    14 条回复    2017-04-14 10:19:45 +08:00
    fengfisher2
        1
    fengfisher2  
       2017-04-01 17:25:17 +08:00
    不知道。
    ryd994
        2
    ryd994  
       2017-04-01 17:25:23 +08:00
    很多地方不太 Pythonic 啊
    if is True:
    https://github.com/intohole/pyct/blob/master/pyct/pyct.py#L81 这是 typo 吧
    各种长段的 elif 可以用 dict 代替
    condition_type 和 time_range , 这明明是个 enum ,为什么枚举用字符串做?

    你是其他语言转 Python 的吧?不光要学会用 Python 写出能跑的程序,还要学着 Pythonic 起来
    mooncakejs
        3
    mooncakejs  
       2017-04-01 17:45:29 +08:00 via iPhone
    仅对楼上, pythonic 是指把 python 语法糖玩的很溜?
    @ryd994
    ryd994
        4
    ryd994  
       2017-04-01 18:05:15 +08:00
    @mooncakejs
    1. 至少可以减少低级 typo
    2. enum 用字符串和用 dict 是 O(n)和 O(logn)的区别
    3. enum 也算语法糖? C 里就有的 enum switch 叫语法糖?你可以找找 Abusing the C switch statement
    ryd994
        5
    ryd994  
       2017-04-01 18:12:22 +08:00
    最后, gmtime 是 UTC , cron 应该是跟随系统时区
    ryd994
        6
    ryd994  
       2017-04-01 18:13:25 +08:00
    @Livid Duplicate with /t/352016
    Allianzcortex
        7
    Allianzcortex  
       2017-04-02 08:51:50 +08:00 via iPhone
    CTItem 的 __equal__ 函数实现的有问题啊
    jyf
        8
    jyf  
       2017-04-02 12:54:32 +08:00
    建议改用 multiprocessing
    intohole
        9
    intohole  
    OP
       2017-04-09 22:19:16 +08:00
    @ryd994 嗯 我工作的时候用 java , 也写 js , shell , c , c++ 我觉得抠语言没意思 , 写东西 写的是思想,我们不是文豪 东西写出来 , 有用 , 能让人看懂就好
    intohole
        10
    intohole  
    OP
       2017-04-09 22:19:29 +08:00
    @ryd994 谢谢你的指点
    intohole
        11
    intohole  
    OP
       2017-04-09 22:20:18 +08:00
    @jyf 谢谢
    intohole
        12
    intohole  
    OP
       2017-04-09 22:20:32 +08:00
    @Allianzcortex 请指教
    Allianzcortex
        13
    Allianzcortex  
       2017-04-12 23:43:23 +08:00
    @intohole 啊啊啊,刚刚看见。我说一下我的感觉哈:

    ```
    def __eq__(self , obj):
    if isinstance(obj , int):
    for condition in self.conditions:
    if condition.judge(obj) is True:
    return True
    return False
    ```
    对应的逻辑是这个意思?:

    ```
    def __eq__(self , obj):
    if isinstance(obj , int):
    for condition in self.conditions:
    if condition.judge(obj) is False:
    return False
    return True
    ```
    intohole
        14
    intohole  
    OP
       2017-04-14 10:19:45 +08:00
    @Allianzcortex 我看下 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5251 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:18 · PVG 17:18 · LAX 02:18 · JFK 05:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.