是否有python3.2的python-notify模块?

时间:2012-10-02 08:50:48

标签: python ubuntu python-3.x notifications pynotify

我已经将一个简单的时差python脚本与我所知道的一起组合在一起,并且它可以在Python 2.7.3中正常工作。该脚本找到时差,然后使用python-notify在Ubuntu中发送桌面通知。

$ cat timediff.py 
import sys
import pynotify
import datetime

now = datetime.datetime.now().replace(microsecond=0)
then = datetime.datetime(2012,11,5,8,0,0)

diff = then - now

hours = (diff.seconds) / 3600
minutes = (diff.seconds - hours * 3600) / 60
seconds = (diff.seconds  - (hours * 3600 + minutes * 60))

def sendmessage(title, message):
    pynotify.init("image")
    notice = pynotify.Notification(title,message,"/usr/share/icons/gnome/48x48/status/important.png").show()
    return notice
sendmessage("Time remaining to exam","%s days, %s hours, %s minutes and %s seconds."% (diff.days,hours,minutes,seconds))

但是,如果我使用Python 3.2.3运行它似乎失败了。似乎Python 3.2没有python-notify模块。

$ python3.2 timediff.py 
Traceback (most recent call last):
  File "timediff.py", line 2, in <module>
    import pynotify
ImportError: No module named pynotify

是否有可能以某种方式使用Python3的python-notify,或者我必须坚持使用Python 2.7,直到为Python 3.2移植绑定?

我发现mailing list dated April 2010表明pynotify可能与Python3不兼容。至少在这方面有没有改进?

1 个答案:

答案 0 :(得分:4)

我没有尝试过,但here is a pynotify replacement

相关问题