
python
文章平均质量分 70
robin_chenyu
这个作者很懒,什么都没留下…
展开
-
python函数中使用全局变量
x = 1def func(): global x x = 2print "old x is: ", xfunc()print "new x is:", x原创 2013-01-10 21:41:55 · 819 阅读 · 0 评论 -
python中的ctypes库初探
python ctypesTable of Contents1 Python中调用C语言库1 Python中调用C语言库Python中提供了ctypes标准库,用来调用C语言库中的函数。加载dll C语言函数存在不同的调用约定,常见的有stdcall和cdecl,这两种调用约定在Python中的调用函数需要区分:stdcall的加载方式:原创 2013-07-28 16:49:52 · 1486 阅读 · 0 评论 -
一个Python中的闭包问题
Table of Contents1 Python中的闭包1.1 用Python实现闭包遇到的问题1.2 nonlocal和global的区别1 Python中的闭包1.1 用Python实现闭包遇到的问题在Python实现分析脚本时,想用闭包实现获取一个递增的id函数,遇到一个问题,在运行时,报外部变量没有找到。 代码如下:def原创 2013-08-04 19:18:15 · 676 阅读 · 0 评论 -
django book学习笔记
Django Book 学习笔记Table of Contents1 django学习点滴1 django学习点滴python ./manage.py shell和python -i的区别 通过manage.py会读取环境变量DJANGOSETTINGSMODULE='djbook.settings'(djbook是工程名) 加载settings中的原创 2013-08-11 19:28:17 · 1240 阅读 · 0 评论 -
Django中的表单类
Django中的表单类Table of Contents1 Djang中表单类1 Djang中表单类Django为我们提供很多有用的模块,其中django.forms.Form类非常不错。 html中一个登录框的格式大致如下: username: password: Django中,通过视图传输的fo原创 2013-08-11 20:10:02 · 1007 阅读 · 0 评论 -
Python笔记
1, Python中下划线命名规则 1. 一个下划线命名的函数和变量,如: _Var或者_Func是不能在其它模块import的,但是可以在子类中使用 2. 两个下划线命名的函数是私有成员,不能import,且子类中也不能访问 3. 两个下划线开始且以两个下划线结束的,是Python中的特殊函数或变量原创 2013-08-14 10:23:10 · 551 阅读 · 0 评论 -
Python中的generator学习
generatorTable of Contents1. Python中的generator学习1.1. Iteration1.2. Generator1.3. Iteration和generator的区别1 Python中的generator学习IterationgeneratorIteration和generator的区别多线程支持情原创 2014-01-05 20:57:05 · 1152 阅读 · 0 评论 -
调用python脚本清理xp系统临时文件
clean_pyTable of Contents1. 清理XP下临时文件脚本1 清理XP下临时文件脚本调用Python程序清理文件夹下的临时文件还是很方便的。import osprofile_dir = os.getenv("USERPROFILE")template_dirs = { 'chrome': "Local Sett原创 2014-01-14 13:38:40 · 904 阅读 · 0 评论 -
virtualenvwrapper安装和配置
virtualenvwrapper安装和配置安装easy_installwget -c https://pypi.python.org/packages/source/e/ez_setup/ez_setup-0.9.tar.gztar xvfz ez_setup-0.9.tar.gzcd ez_setup-09python ./ez_setup.py安装pipe原创 2014-02-12 14:25:19 · 4095 阅读 · 0 评论 -
django和mezzanine搭建博客小站1
django和mezzanine搭建博客小站1用Django+mezzanine搭建个人博客非常简单,基本上安装和简单的配置就可以完成。搭建环境安装Python编译器sudo apt-get install python安装pip,virtualenv,virtualenvwrapper- pip是Python的安装包管理系统- virtualenv是搭建Pyth原创 2014-02-19 10:07:07 · 2211 阅读 · 0 评论 -
Django,uwsgi,nginx简单配置
django_uwsgi_nginxTable of Contents1. Django部署1.1. uwsgi的部署1.2. nginx的部署1 Django部署django+uwsgi+nginx部署环境总结。http请求先到nginx,如果是静态页面,nginx直接获取静态页面返回结果;对于动态页面,则交给uwsgi进行处理,uwsgi原创 2014-03-17 11:03:36 · 1656 阅读 · 0 评论 -
django开发微信简单消息交互
django_weixinTable of Contents1. Django开发WeiXin简单消息交互1.1. 在开发过程中,主要问题1 Django开发WeiXin简单消息交互WeiXin接口全是xml格式的,非常简单,开发消息交互,主要有一下几个步骤:申请公众账号,并通过开发者验证开发服务端程序,实现接入流程验证,并需要架设到原创 2014-03-18 14:05:03 · 1482 阅读 · 0 评论 -
python3连接sybase
python33连接sybase可以用pypyodbcpython33中可以使用ctype包装c语言动态库太方便了原创 2013-07-04 21:33:48 · 8548 阅读 · 1 评论 -
Python中的metaclass
<!--html {font-family:Times,serif; font-size:12pt}.title {text-align:center}.todo {color:red}.done {color:green}.tag {background-color:#add8e6; font-weight:normal}.timestamp原创 2013-07-18 22:43:08 · 1106 阅读 · 0 评论 -
python单引号、双引号和三双引号的区别
先说1双引号与3个双引号的区别,双引号所表示的字符串通常要写成一行 如: s1 = "hello,world" 如果要写成多行,那么就要使用\ (“连行符”)吧,如 s2 = "hello,\ world" s2与s1是一样的。如果你用3个双引号的话,就可以直接写了,如下: s3 = """hello, world, hahaha.""",那么s3实际上就是"h转载 2013-01-11 21:11:33 · 594 阅读 · 0 评论 -
python socks5 proxy实现
zz http://www.ietf.org/rfc/rfc1928.txt http://www.ietf.org/rfc/rfc1929.txtimport socket, sys, select, SocketServer, struct, timeclass ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.原创 2013-01-12 21:02:39 · 24084 阅读 · 0 评论 -
日志分析器
日志根据时间有一定的显示,可以根据这个做日志分析消息流程import reimport fnmatchimport osimport timeimport syslogfiles = []class SmtransStats: def __init__(self, interval = 1): self.stats = {原创 2013-01-15 18:50:32 · 620 阅读 · 0 评论 -
评书下载器
# -*- coding: cp936 -*-try: import urllib.request as urllib2except ImportError, details: import urllib2import urllibimport reimport osimport sysmain_url = 'http://www.5ips.net'def ge原创 2013-02-05 13:30:51 · 1401 阅读 · 0 评论 -
python中可变参数个数参数
argsTable of Contents1 python中可变参数1.1 以tuple类型传递1.2 以dict类型传递1 python中可变参数1.1 以tuple类型传递def argTest(*args): print(args, type(args)) for i in args: pri原创 2013-04-13 21:57:42 · 2396 阅读 · 0 评论 -
python decorator
<!--html {font-family:Times,serif; font-size:12pt}.title {text-align:center}.todo {color:red}.done {color:green}.tag {background-color:#add8e6; font-weight:normal}.timestamp原创 2013-04-15 16:01:38 · 792 阅读 · 0 评论 -
python中类与函数的关系
<!--html {font-family:Times,serif; font-size:12pt}.title {text-align:center}.todo {color:red}.done {color:green}.tag {background-color:#add8e6; font-weight:normal}.timestamp原创 2013-04-15 16:14:26 · 1425 阅读 · 0 评论 -
python中的类
<!--html {font-family:Times,serif; font-size:12pt}.title {text-align:center}.todo {color:red}.done {color:green}.tag {background-color:#add8e6; font-weight:normal}.timestamp原创 2013-04-16 16:37:33 · 953 阅读 · 0 评论 -
Python3中bytes和HexStr之间的转换
<!--html {font-family:Times,serif; font-size:12pt}.title {text-align:center}.todo {color:red}.done {color:green}.tag {background-color:#add8e6; font-weight:normal}.timestamp原创 2013-05-29 15:52:32 · 10586 阅读 · 1 评论 -
强大的ctype
有了ctype之后,python用C语言的库不再需要用C写转换函数。1. 载入动态库 #include // file libHi.c#include int hi(const char *str){ printf("Hi %s\n", str); return 0;}然后编译为动态库 gcc -shared -fPIC -o libHi.so lib原创 2013-07-06 22:22:31 · 1143 阅读 · 0 评论 -
Python中的数据模型
Python中的数据模型__new__ 与 __init__ 的区别__new__在__init__之前调用__new__在返回一个类的实例时,会调用类的__init__函数__new__没有返回类的实例,或者返回的实例对应的类没有__init__,则不会调用__init__type与object作为父类的区别metaclass定义父类的含义type.new() -->原创 2013-07-17 23:37:29 · 865 阅读 · 0 评论 -
Python中使用Threads和Queue给tornado添加客户端
python_threadsTable of Contents1. Python中使用Threads和Queue实现数据同步1 Python中使用Threads和Queue实现数据同步在使用tornado实现web服务器时,遇到需要使用客户端反向发送POST请求。在Handler中直接使用tornado客户端性能会受到影响,如果使用异步客户端(Async原创 2014-05-05 19:46:30 · 2397 阅读 · 0 评论