原来发过一个Python下的换桌面脚本,由于相关网站改版,脚本失效.。我也相应更新一下。移除了图片质量一般的EPOD。充分测试了windows(XP) 和 linux(Ubuntu gnome)双平台. 同时将原有的拉伸全屏模式,更改为保持长宽比的居中模式(其他模式的使用参数也已写在注释中)。 对于APOD,可以手动指定更新任意一天的图片(只支持JPG), 而NGPOD的网站地址与时间无关,只能获取最新图片。下载前会检查文件名,如果图片已经存在,则自动跳过。默认下载大图,然后根据设定分辨率生成桌面图片。各项参数要在源码中自行调整。仍需要PIL模块支持,这个模块的详细介绍可以看这里。新脚本点此下载。
继续阅读
标签归档:code
发表评论
Simbad座标查询脚本
Python中文排序
Python比较字符串大小时,根据的是ord函数得到的编码值。基于它的排序函数sort可以很容易为数字和英文字母排序,因为它们在编码表中就是顺序排列的。
1 2 |
>> print ','< '1'<'A'<'a'<'阿' True |
但要很处理中文就没那么容易了。中文通常有拼音和笔画两种排序方式,在最常用中文标准字符集GB2312中,3755个一级中文汉字是按照拼音序进行编码的,而3008个二级汉字则是按部首笔画排列,
1 2 |
>> print '曙'< '鲑','曾'<'怡' True True |
出现这样的结果是因为‘曙’和‘曾’都是常用字,而‘鲑’和‘怡’都是次常用字,但无论从笔画还是拼音来看,这两对顺序都应该反过来。后来扩充的GBK和GB18030编码为了向下兼容,都没有更改之前的汉字顺序,于是sort之后的次序就很乱了。
继续阅读
误差棒函数1.1
应读者要求,为Matlab误差棒函数增强版加入了颜色和点型控制功能,顺便加了个英文说明,上传到Mathworks 社区,点此访问,这才发现已经有了那么多类似的函数,果然工作还是要趁早啊,看论文去了……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
% ERRORBARE Enhanced Errorbar Function. % ERRORBARE(STY,X,Y,Xbar,Ybar,symbol) % It can draw errorbar along X/Y/Dual axis % in normal,semilog,loglog coordinate system, % and adjust width of bar handles automatically, % can also control dotstyle/color in the same way with errorbar. % % If the lower and upper error range of x/y is different, % they should be input as [lower,upper] if x/y is a column vector; % for a row vector, they should be [lower;uper]. % % parameter STY include 12 types: % v,h,d,vlogx,hlogx,dlogx,vlogy,hlogy, % dlogy,vlogd,hlogd,dlogd % where % v stands for vertical errorbar, % h draws horizontal errorbar, % d means dual direction, % logx corresponding to semilogx,can use preffix v/h/d % logy corresponding to semilogy,can use preffix v/h/d % logd corresponding to loglog,can use preffix v/h/d <!--more--> % 误差棒函数增强版 % ERRORBARE(STY,X,Y,Xbar,Ybar,symbol) % 可在各个坐标系中沿X轴,Y轴方向,或者两轴方向绘制误差棒, % 能够根据所选坐标类型调整端点线长。 % 增加对误差棒的线型控制,用法与原errorbar函数中相同 % % 若上下限范围不同,X为列向量时应按照 % [下限,上限] 的格式输入,若为行向量则为 [下限;上限] % % STY 参数包括 v,h,d,vlogx,hlogx,dlogx,vlogy,hlogy, % dlogy,vlogd,hlogd,dlogd 共12种 % v 表示误差棒垂直, % h 表示误差棒水平, % d (dual) 显示双轴误差, % logx 对应 semilogx,前缀 v,h,d 意义同上 % logy 对应 semilogy,前缀 v,h,d 意义同上 % logd 对应 loglog,前缀 v,h,d 意义同上 % For example, % x = 1:10; % y = sin(x)+2; % e = std(y)*ones(size(x)); % errorbare(x,y,e) % use function "errorbar" directly % errorbare(x,y,e,'or') % errorbare('v',x,y,e) % "e" is error of "y" % errorbare('v',x,y,[e;2*e]) % try different error limits % errorbare('hlogx',x,y,e) % "e" is error of "x" here, % errorbare('d',x,y,e,e) % errorbare('d',x,y,e,e,'or') % errorbare('dlogd',x,y,e,e) % % by Heng Yu Email: henrysting@hotmail.com % $Revision: 1.1 $ $Date: 2009/03/28 $ |
python脚本换桌面
原来何勃亮发过一个gnome下自动更新每日天图(APOD)作为桌面的脚本,挺有意思的,我这里发一个Python的,可以看作是免费软件Pic-a-POD和Picture of the Day的替代品,在2.6下测试通过,需要安装PIL库,可以自行选择天文每日一图(APOD)、地理每日一图(EPOD)、或者美国国家地理每日一图(NGPOD),点此下载。
这是由seasons的版本修改而来,他那里漏了一个setWallpaperFromBMP函数,还好在他的 javaEye 日志中找到了,有人是用win32gui实现,不过我测试没有成功。
源码如下,方便引擎收录:)
继续阅读