
Python
海之子99
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Hello PyGTK!
<br />#!/usr/bin/python<br /><br /> import pygtk<br /> pygtk.require('2.0')<br /> import gtk<br /><br /> window = gtk.Window(gtk.WINDOW_TOPLEVEL)<br /> window.show();<br /> Test = "Hello World PyGTK!";<br /> button = gtk.Button(Test);<br /> window.原创 2010-07-03 18:41:00 · 682 阅读 · 0 评论 -
Mac安装Tornado
在命令行下执行: sudo easy_install setuptools pycurl 过程中可能会出错: In file included from src/docstrings.c:4: In file included from src/pycurl.h:4: /System/Library/Frameworks/Python.framework/Versions/2.7/i原创 2015-03-04 19:25:05 · 444 阅读 · 0 评论 -
SQLAlchemy 和其他的 ORM 框架
http://www.oschina.net/translate/sqlalchemy-vs-orms转载 2015-03-02 19:06:46 · 580 阅读 · 0 评论 -
Python如何获取JPG图片的长宽等信息
使用PIL模块,windows安装包下载: http://www.pythonware.com/products/pil/ 使用方法 # coding: utf8 # 获取指定图片的长和宽 from PIL import Image img = Image.open("img.jpg") print img.size 运行结果: (52, 54)转载 2015-01-13 08:58:45 · 18296 阅读 · 0 评论 -
Python脚本的文件、目录处理
import os import os.path os.path.join(os.getcwd(), os.listdir('.')[2])原创 2013-09-26 13:48:45 · 160 阅读 · 0 评论 -
Python读写二进制数据文件
#!/usr/bin/python import struct print "This scripts test reading & writing files" f = open("./test.txt", "wb") # Data to write data = range(100000000001,100000000099) datalen = len(d原创 2013-11-08 17:01:14 · 1008 阅读 · 0 评论 -
非常有用的Python命令dir() - 列出某个类型的所有可用方法
列出字符串数据类型的所有方法,参数可以是类型type或此类型的对象! >>> dir(str) 或 dir("") ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',原创 2013-09-05 20:23:20 · 12212 阅读 · 0 评论 -
Python tuple 元组详解
Tuple 是不可变 list。 一旦创建了一个 tuple 就不能以任何方式改变它。 Tuple 与 list 的相同之处 定义 tuple 与定义 list 的方式相同,除了整个元素集是用小括号包围的而不是方括号。 Tuple 的元素与 list 一样按定义的次序进行排序。 Tuples 的索引与list 一样从 0 开始, 所以一个非空 tuple 的第一个元素总是 t[0转载 2013-09-05 14:42:57 · 8948 阅读 · 0 评论 -
用Python xlrd对比两个Excel文件的差异diff
对于经常使用Excel作数据处理的任务,时常需要了解某个Excel文件相对于之前作了哪些修改。 下边提供我最近编写的一个diff两个Excel文件的Python脚本,用到了xlrd库。 #!/usr/bin/python #coding=gbk # 用法:python diff_excel.py [file1] [file2] from xlrd import open_workbook i原创 2013-08-24 10:54:38 · 7803 阅读 · 0 评论 -
用Python正则表达式搜索统计命令行管道中的所有数字
用Python正则表达式搜索统计Shell命令行管道中的所有数字原创 2013-08-23 09:23:31 · 3629 阅读 · 1 评论 -
Python中使用正则表达式
本文通过示例来描述如何在Python中使用正则表达式来统计文本中的所有数字。 示例中的文本来自命令行的管道数据, sys.stdin.readlines() 主要是因为作者需要在命令行的输出信息中做数字统计。 示例代码1,列出根目录下所有文件或文件夹的名称字符串中包含的数字 import re for name in sys.stdin.readlines():原创 2013-07-30 19:49:05 · 40210 阅读 · 1 评论 -
Python脚本中使用命令行管道数据
Python脚本中使用命令行管道数据的示例 test.py: import sys; print sys.argv; names = {} names = sys.stdin.readlines() print names 执行命令行: $ ls / | python test.py 输出结果:(根目录下的所有文件和目录) ['test.py'] ['bin\n',原创 2013-07-30 19:17:35 · 4340 阅读 · 0 评论 -
Python 读写 Excel
Python 读写 Excel 基本上, 这个网页已经说明一切了: http://pypi.python.org/pypi/xlrd 等有时间再把这个页面写漂亮,现在先记一些代码. 读Excel 先建个simple.xls from xlrd import open_workbook wb = open_workbook('simple.xls','rb')转载 2012-08-03 14:44:33 · 798 阅读 · 0 评论 -
用python把一个目录中的所有文件拷贝到指定目录
把目录(包括子目录)中的所有文件,拷贝到指定的目录中,并重命名为 [n][.ext],即文件以数字顺序为名字并加上原有扩展名。 import os import shutil def walk_dir(dir,topdown=True): fileList = [] for root, dirs, files in os.walk(dir, topdown):原创 2012-05-02 00:20:07 · 5278 阅读 · 0 评论 -
Python读写Excel库:xlrd & xlwt
Python读写Excel库:xlrd & xlwt class ExcelReader class ExcelWriter原创 2011-11-29 19:45:27 · 340 阅读 · 0 评论 -
Python相关的一些资源链接
Unofficial Windows Binaries for Python Extension Packages http://www.lfd.uci.edu/~gohlke/pythonlibs/原创 2011-08-14 13:53:46 · 190 阅读 · 0 评论 -
Using Python in Sqlite !
http://docs.python.org/library/sqlite3.htmlNew in version 2.5.SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQ原创 2010-07-03 20:38:00 · 777 阅读 · 0 评论 -
Python相关网站
一个非常好的中英对照的Python语言教程:http://www.woodpecker.org.cn:9081/doc/Python/Py2.4tut/html/tut.htmlPython GTK:http://www.pygtk.org/tutorial.html原创 2010-07-03 16:02:00 · 684 阅读 · 0 评论 -
mac下安装pycurl报错的解决办法
解决办法: PATH=/usr/bin: $PATH python setup.py install (源码安装方式, 其他应类似) 参考这里: https://github.com/tornadoweb/tornado/wiki/Installation-Troubleshooting转载 2015-05-01 22:03:04 · 1693 阅读 · 0 评论