python的一些操作
# coding=gb2312
# 用中文注释前务必加上第一行
# 求模运算符,和C语言一样
print 10%9
# 整数相除仍然是整数
print 5/2
# 2后加上.就变成浮点数了
print 5/2.
# **表示求幂运算
print 7**4
# 函数用时要加上module.function
import math
print math.floor(19.8)
# 函数名也可以成为变量
func = math.floor
print func(1.9)
# 可以用 + 来连接两个字符串
print "abc" + "def"
# 如果句子中有 ’,可以用\'代替
print 'He\'s a student'
# 或者用双引号
print "He's a teacher"
# 字符串可以索引
print "abcdefgf"[3]
# 将数字变成字符串的三种方法
x = 12345
print 'number:' + str(x)
print 'number:' + repr(x)
print 'number:' + `x`
# 输入数字的方法
x = input('Please Enter a number:')
print x
# 输入字符串的方法
xx = raw_input();
#print xx
# 程序结尾可以加上这一行,程序就不会一闪而过了
raw_input('Press Enter to Continue...')
相关文档:
我们在做软件开发的时候很多要用到多线程技术。例如如果做一个下载软件象flashget就要用到、象在线视频工具realplayer也要用到因为要同时下载media stream还要播放。其实例子是很多的。
线程相对进程来说是“轻量级”的,操作系统用较少的资源创建和管理线程。程序中的线程在相同的内存空间中执行,并共享许多 ......
#快速排序
def Partition(mylist, low, high):
tmp = mylist[low]
while low < high:
while low < high and mylist[high] >= tmp:
high = high - 1
if low < high:
mylist[low] = mylist[high]
low = low + 1
while low < hi ......
#使用类
class CPerson:
#类变量好比C++中的静态成员变量
population = 0
def SayHi(self):
print('Hello World')
def HowMany(self):
if CPerson.population == 1:
print('I am the only person here.')
else:
print(('We have %d perso ......
参考链接:http://www.woodpecker.org.cn/diveintopython/functional_programming/dynamic_import.html
一 动态导入模块
Python的import不能接受变量,所以应该用 __import__函数来动态导入。
如下的代码无法正常导入模块
modules = ['OpenSSL', 'Crypto', 'MySQLdb', 'sqlite3', 'zope.interface', 'pyasn1', 'twisted ......