易截截图软件、单文件、免安装、纯绿色、仅160KB

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...')


相关文档:

python算法实践4 快速排序

#快速排序
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 ......

python算法实践5 直接选择排序

#直接选择排序
def SelectSort(mylist):
size = len(mylist)
i = 0
for i in range(0, size):
k = i
for j in range(i + 1, size):
if mylist[j] < mylist[k]:
k = j

if k != i:
tmp = mylist[i]
......

python学习1 使用类

#使用类
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 ......

Python安装MySQLDb模块的种种问题及解决


我的环境是:Linux version 2.4.21-4.EL
(bhcompile@daffy.perf.redhat.com) (gcc version 3.2.3 20030502 (Red Hat
Linux 3.2.3-20)) #1 Fri Oct 3 18:13:58 EDT 2003 + Python2.6.4
本文结合我安装时候的问题,总结而成
用户目录如/home/liuguanyu/ , 保证用户有root权限
1,看看有没有安装
 &nbs ......

python动态导入模块、检查模块是否安装

参考链接:http://www.woodpecker.org.cn/diveintopython/functional_programming/dynamic_import.html
一 动态导入模块
Python的import不能接受变量,所以应该用 __import__函数来动态导入。
如下的代码无法正常导入模块
modules = ['OpenSSL', 'Crypto', 'MySQLdb', 'sqlite3', 'zope.interface', 'pyasn1', 'twisted ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号