clowwindy的杂草牧场

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  34 随笔 :: 1 文章 :: 75 评论 :: 13万 阅读

随笔分类 -  Python

摘要:今天发现ipad在ubuntu上会一直显示Not Charging,搜了一下,发现有人写了一个ipad_charge程序:https://github.com/mkorenkov/ipad_charge/看了一下源码,是通过发一个控制指令实现开始和停止充电的。于是用pyusb(apt-get install python-usb)移植了一下:#!/usr/bin/pythonimport usb.coreimport usb.utilimport usb.backend.libusb10import sys, getoptopts = getopt.getopt(sys.argv[1:],&# 阅读全文
posted @ 2011-12-28 15:57 clowwindy 阅读(2628) 评论(0) 推荐(0) 编辑

摘要:今天在用py2exe的时候,发现如果把exe设为随windows自动启动,无法用相对路径加载资源文件。研究了一下之后发现,自启动的程序的当前目录在c:/users/username下,而双击exe运行时当前目录在exe所在目录。查了一下py2exe文档,提到了获取exe路径的办法。所以,我们只需要在第一行代码执行前,cd到exe所在目录,就能保证相对路径没有问题了:os.chdir(os.path.dirname(sys.executable)) 阅读全文
posted @ 2011-10-31 15:55 clowwindy 阅读(733) 评论(0) 推荐(0) 编辑

摘要:这几天在做项目打包的时候,因为要保护知识产权,所以将py文件编译成pyc文件再打包。于是研究了一下,编译的方法很简单,用compileall.compile_dir()函数就可以了。首先,将项目拷贝到一个目录(过滤掉.开头的隐藏文件),然后编译,最后删除.py文件。这里有一个问题,就是原来的源码目录下可能已经有pyc了,所以在编译的时候要指定force=1强制编译一下,覆盖掉这些文件。下面是打包脚本:BUILD_PATH = 'build/'PROJECT_PATH = 'src/'import osimport os.pathimport shutilimpo 阅读全文
posted @ 2011-10-26 16:54 clowwindy 阅读(1500) 评论(0) 推荐(0) 编辑

摘要:这是上次urllib2版的升级版,直接放在Google AppEngine上跑,顺便加了星成就。不得不吐嘈某人让题目跟答案一起POST,于是不用每次解析出题目组织答案了。#!/usr/bin/env pythonfrom google.appengine.ext import webappfrom google.appengine.ext.webapp import utilfrom google.appengine.api.urlfetch import fetchimport reclass CronHandler(webapp.RequestHandler): def get(se... 阅读全文
posted @ 2010-09-12 14:26 clowwindy 阅读(2900) 评论(0) 推荐(0) 编辑

摘要:I'm using django with a legacy mysql db which uses TIMESTAMP columns. Django's inspectdb recognize those fields as int fields. This caused troubles if you want to render its value into a readable date. I googled and found this solution:http://ianrolfe.livejournal.com/36017.html代码Code highlig 阅读全文
posted @ 2010-09-11 18:34 clowwindy 阅读(3267) 评论(0) 推荐(0) 编辑

摘要:python code:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#!/usr/bin/envpythonimportcodecsimporturllibimportcookielibimporturllib2fromtimeimportstrftimeparams={'jumpurl':'/','step':'2','cktime':'311536 阅读全文
posted @ 2010-01-02 07:59 clowwindy 阅读(2363) 评论(3) 推荐(0) 编辑

点击右上角即可分享
微信分享提示