
python
Alps
这个作者很懒,什么都没留下…
展开
-
python音标html实体转换
例如:音标ə 用hmtl实体表示为ə反过来转换为unichr(601).encode('utf-8')或者unichr(int('0x259', 16)).encode('utf-8') 国际音标与html实体转换列表http://tlt.its.psu.edu/suggestions/international/b原创 2013-02-20 13:20:06 · 1793 阅读 · 0 评论 -
python安装相关
setuptoolspython2.6wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gzpython setup.py buildpython setup.py install原创 2013-12-11 11:16:38 · 796 阅读 · 0 评论 -
python easy_install离线安装方式
http://blog.youkuaiyun.com/turkeyzhou/article/details/88808871. 下载ez_setup.py。Linux下可使用此命令: wget -q http://peak.telecommunity.com/dist/ez_setup.py。2. 运行ez_setup.py:python ez_setup.py ;如果运行正常,那就安装转载 2013-11-20 19:30:20 · 3618 阅读 · 0 评论 -
python取文件路径
__file__为所在.py文件的完整路径,但是这个变量有时候返回相对路径,有时候返回绝对路径,因此还要用os.path.realpath()函数来处理一下。文件路径:os.path.realpath(__file__)目录路径:os.path.split(os.path.realpath(__file__))[0]原创 2013-10-07 08:31:18 · 926 阅读 · 0 评论 -
python上传文件
http://ruby4u.iteye.com/blog/299699mechanize# 文件的上传# 方法一page.forms[0].file_uploads.name('upfile').file_name = './hoge.jpg'# 方法二page.forms[0].file_uploads.name('upfile').file_data = File.原创 2013-04-03 11:57:00 · 965 阅读 · 0 评论 -
django一些头信息
HttpRequestHttpRequest代表一个来自uesr-agent的HTTP请求。大多重要的请求信息都是作为HttpRequest 对象的属性出现(see Table H-1). 除了session外,其他所有属性都是只读的。Table H-1. HttpRequest对象的属性 AttributeDescription path 请求页面的全路径,不包括域名—例如, "/mus原创 2013-02-26 19:55:18 · 1216 阅读 · 0 评论 -
python动态加载模块及变量是否存在方法
动态加载模块有三种方法1,使用系统函数__import_()stringmodule = __import__('string')2,使用imp 模块import imp stringmodule = imp.load_module('string',*imp.find_module('string'))3,使用execimport_string = "impo原创 2013-02-26 19:53:24 · 1558 阅读 · 0 评论 -
Django源码分析--引导
django有两种运行方式1,通过python manage.py runserver运行自带的web server2,通过mod_python两种方式但最后的request生成方法都是继承自django.http.HttpReques第一种方式, runserver参数最后实际执行的是django.core.management.commands.runserver模块r原创 2013-02-27 12:47:26 · 863 阅读 · 0 评论 -
python获取运行位数
import platformplatform.architecture()('32bit', 'WindowsPE') 在某些64系统上python可运行在32位模式下,OS X 10.6$ /usr/bin/pythonPython2.6.1(r261:67515,Jul 72009,23:51:51)[GCC 4.2.1(AppleInc. bu原创 2013-02-26 19:51:28 · 3553 阅读 · 0 评论 -
python陷阱
1,虚函数class check_base(object): def dt(self): self.__pr() def __pr(self): print 'base' pass class check_blog(check_base):原创 2013-02-26 19:48:30 · 619 阅读 · 0 评论 -
python接收邮件
1.poplib.POP3('这里填入你pop邮件服务器地址') 登陆服务器. 2.poplib.user('用户名 ') poplib.pass_('密码') 3.poplib.stat()方法返回一个元组:(邮件数,邮件尺寸) mailCount,size=poplib.stat() 这样mailCount就是邮件的数量,size,就是所有邮件的大小.4.poplib.原创 2013-02-26 19:49:30 · 1394 阅读 · 0 评论 -
python技巧
1,去重Python列表去掉重复元素的一种方法:>>> L = [1, 2, 3, 4, 1, 2, 3, 4, 5]>>> [x for x in L if x not in locals()['_[1]']][1, 2, 3, 4, 5]或者list(set(a)) 2,对象排序list 排序在包含某元素的列表中依据某个属性排原创 2013-02-23 16:08:38 · 605 阅读 · 0 评论 -
django使用innodb类型表commit
from django.db import connection cursor = connection.cursor() cursor.execute("delete from event where id=%s",[event_id]) cursor.close() innodb在上面情况下,不会生效,cursor.close() 并没有进行commit原创 2013-02-23 16:07:43 · 890 阅读 · 0 评论 -
mysqldb按字典方式取数据
1,conn=MySQLdb.Connect(host='localhost',user='root',passwd='',db='test',compress=1,cursorclass=MySQLdb.cursors.DictCursor)cursor=conn.cursor()2,c = self.db.cursor(cursorclass=MySQLdb.c原创 2013-02-23 16:09:17 · 1013 阅读 · 0 评论 -
python time,datetime,string转换
#把datetime转成字符串 def datetime_toString(dt): return dt.strftime("%Y-%m-%d %H:%M:%S") #把字符串转成datetime def string_toDatetime(string): return datetime.strptime(string原创 2013-02-20 13:44:39 · 647 阅读 · 0 评论 -
python new objects by subclassing
http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html关于新类的更多特性和使用方法,参考:Unifying types and classes in Python 2.2How-To Guide for Descriptorshttp://hi.baid原创 2013-02-20 13:19:41 · 765 阅读 · 0 评论 -
python内存
python使用引用计数(1)用户显示调用gc.collect()(2)当gc模块被使用后,每次Python为新对象分配内存时,都会检查当前分配对象的数目是否超过了gcmodule规定的threshold。如果超过,即表明分配的对象数目已经很多,应该进行垃圾回收了。此时gc模块自动开始垃圾回收工作。 3. 如何检测Python中的内存泄露GC原创 2013-02-20 13:19:14 · 620 阅读 · 0 评论 -
python setuptools离线安装方法
下载setuptools的egg包来安装。可以在 这里 查看最新版本下载。下载完毕以后通过sh安装。$ wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg$ sudo sh setuptools-0.6c11-py2.6.egg原创 2014-08-27 17:36:52 · 4998 阅读 · 0 评论