日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python跨文件引用模块

發布時間:2025/3/15 python 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python跨文件引用模块 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

想作一個python模塊庫,自己時時調用。

文件層級結構

~/bin:

---pylib pybin

~bin/pylib:

---notify __init__.py

~bin//pybin:

---ct_weather.py

~/bin/pylib/notify

---ct_notifyGTK.py __init__.py

~bin/pylib/__init__.py

import notify __all__ = ['notify'] ~/bin/pylib/notify/__init__.py

import ct_notifyGTK __all__ = ['ct_notifyGTK']

ct_notifyGTK.py

import gtk import pynotify notification = 0 def callback(icon):notification.show() def ct_notify(title, body, timeout = pynotify.EXPIRES_NEVER, type = 'notype'):pynotify.init(title)global notificationnotification = pynotify.Notification(title, body, type)notification.set_urgency(pynotify.URGENCY_NORMAL)notification.set_timeout(timeout)icon = gtk.status_icon_new_from_stock(gtk.STOCK_ABOUT)icon.connect('activate', callback)notification.attach_to_status_icon(icon)gtk.main() if __name__ == '__main__':ct_notify('weather', 'rain/n3oC') ct_weather.py

#import sys #sys.path.append('/home/ct/bin/pylib') from notify import ct_notifyGTK from urllib import urlopen import re p = re.compile('<[^>]+>') def ct_getweather(url = /"http://www.weather.com.cn/wap/weather/101010100.shtml"):'''ct_getweather: return the encoded in utf8 texts represents weathercondition.No description.'''sock = urlopen(url)htmlsource = sock.read()sock.close()content = p.sub("", htmlsource)content = '/n'.join(content.split()[1:12])return content.decode('utf8') #------end of ct_getweather() -------------------------------------------------- if __name__ == '__main__':weather = ct_getweather()ct_notifyGTK.ct_notify('Weather In Beijing', weather) #設置PYTHONPATH

#!/bin/bash echo "export PYTHONPATH=~/bin/pylib" >> ~/.bashrc

?


?

總結

以上是生活随笔為你收集整理的Python跨文件引用模块的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。