Python代码备忘

学习,练习,记录

导航

#

[置顶] Python 相关常用重要链接收集(不断更新)

摘要: [00]http://www.ppurl.com/tag/python说明:Python 电子书下载地址,多是英文。皮皮书屋是下载计算机相关书籍的好地方。[01]http://www.lfd.uci.edu/~gohlke/pythonlibs/说明:非官方 Python 扩展 Windows 安装包,常用的 Python 扩展包都齐全。[02]http://woodpecker.org.cn/ http://wiki.woodpecker.org.cn/moin/(Wiki)说明:啄木鸟社区,Python 的开源社区,学习 Python 的好地方。[03]http://code.googl. 阅读全文

posted @ 2012-03-14 15:01 sysuoyj 阅读(331) 评论(0) 推荐(0) 编辑

2012年3月23日 #

PyQt4中pyrcc4和pyuic4的使用

摘要: 写了个PyQt4的程序,用desiger设计了个界面,使用了Qt的rcc系统。于是研究了一下pyrcc4和pyuic4的使用方法,其实都很简单,pyrcc4 -o ui_form.py form.ui,pyuic4同样的用法。由于用到了好几个ui,一行行的敲着挺麻烦,于是边看python帮助写了个辅助的生成脚本:import osfor root, dirs, files in os.walk('.'): for file in files: if file.endswith('.ui'): os.system('pyuic4 -o ui_%s.py . 阅读全文

posted @ 2012-03-23 16:41 sysuoyj 阅读(3202) 评论(0) 推荐(0) 编辑

2012年3月21日 #

Python中时间戳与时间字符串互相转化

摘要: #设a为字符串import timea = "2011-09-28 10:00:00"#中间过程,一般都需要将字符串转化为时间数组time.strptime(a,'%Y-%m-%d %H:%M:%S')>>time.struct_time(tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=10, tm_min=50, tm_sec=0, tm_wday=1, tm_yday=270, tm_isdst=-1)#将"2011-09-28 10:00:00"转化为时间戳time.mktime( 阅读全文

posted @ 2012-03-21 16:07 sysuoyj 阅读(428) 评论(0) 推荐(0) 编辑

2012年3月19日 #

简化字符串的 translate 方法的使用

摘要: import stringdef Translator(frm = '', to = '', delete = '', keep = None): if len(to) == 1: to = to * len(frm) trans = string.maketrans(frm, to) if keep is not None: allchars = string.maketrans('', '') delete = allchars.translate(allchars, keep.translate(allcha 阅读全文

posted @ 2012-03-19 13:14 sysuoyj 阅读(319) 评论(0) 推荐(0) 编辑

2012年3月15日 #

Python进制转换(二进制、十进制和十六进制)

摘要: 来源:http://www.cnblogs.com/zhangpengshou/archive/2012/03/12/2392068.html#!/usr/bin/env python# -*- coding: utf-8 -*-# 2/10/16 base trans. wrote by srcdog on 20th, April, 2009# ld elements in base 2, 10, 16.import os,sys# global definition# base = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F]base = 阅读全文

posted @ 2012-03-15 20:28 sysuoyj 阅读(835) 评论(0) 推荐(0) 编辑

2012年3月14日 #

Python 学习-常用工具

摘要: 来源:Elias整理http://www.elias.cn/Python/HomePage?from=Develop.Python1. 基本安装http://www.python.org/官方标准Python开发包和支持环境,同时也是Python的官方网站;http://www.activestate.com/集成多个有用插件的强大非官方版本,特别是针对Windows环境有不少改进;2. Python文档Python库参考手册Python 2.7 Tutorial 中文版(有可能需FQ)(Python 其他版本的教程翻译见译者主页)Byte of Python可以代替Tutorial使用,.. 阅读全文

posted @ 2012-03-14 14:40 sysuoyj 阅读(1793) 评论(0) 推荐(1) 编辑

Python程序输出到文件中

摘要: 来源:Python参考手册要将程序的输出送到一个文件中,需要在 print 语句后面使用 >> 指定一个文件,如下所示:principal = 1000 # 初始金额rate = 0.05 # 利率numyears = 5 # 年数year = 1f = open("out.txt", "w") # 打开文件以便写入while year <= numyears: principal = principal * (1 + rate) ... 阅读全文

posted @ 2012-03-14 14:19 sysuoyj 阅读(42497) 评论(0) 推荐(0) 编辑

Python逐行读取文件内容

摘要: 代码来源: Python参考手册f = open("foo.txt") # 返回一个文件对象line = f.readline() # 调用文件的 readline()方法while line: print line, # 后面跟 ',' 将忽略换行符 # print(line, end = '') # 在 Python 3中使用 line = f.readline()f.close()也可以写成以下更简洁的形式for line in open("foo.txt"): print lin... 阅读全文

posted @ 2012-03-14 13:32 sysuoyj 阅读(163692) 评论(0) 推荐(4) 编辑