Lovely Python整理
Python - 弱数据类型,不需要强制声明
Python - 一切都是对象
Pyhton - 语句块以:结尾,并且下句缩进
Python - 复用级别 代码行→函式→类→模块
Python - 支持函数
Python - KISS原则 == Keep It Simple,Stupid
一、中文支持
# -*- coding: utf-8 -*-
二、使用模块
import os, sys,cmd
fromt cdctools.py import *
from threading import Thread #多线程
三、模块
os.listdir('path');
os.walk('path')
文件操作
open('fileName','a/w').write('content');
四、函数
def method(param1,param2):
doSomething
五、命令行交互
import sys
sys.arg[x]
六、类
class ClassName(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
if __name__ == ' __main__ ':
doSomething
线程
class grepIt(Thread):
def __init__(self,param1,param2):
Thread.__init__(self)
七、语法
filelist = os.listdir('path')
for cdc in filelist:
if ".cdc" in cdc:
if keword in line:
print line
异常捕获
try:
for type in tryuni:
try:
ustring = unicode("%s}"%type+stream, type)
#try decode by list
except:
continue
#break!continue try decode guess
except:
return u"bad unicode encode!"
八、其他工具
chardet 编码探测
epydoc py文档生成器
ConfigParser 文件操作API
Web框架
Karrigell WebFrameworks
web.py
九、其他
桌面开发 Tk/Tcl Qt WxPython win32com