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

Python学习笔记 高级主题

1.列表的递归---用于输出列表字符串中的每个元素 >>> def printList(L):
    #如果为空,则什么都不做
    if not L:
        return
    #如果是链表,则对第一个元素调用printList函数
    if type(L[0])==type([]):
        printList(L[0])
    else:#如果不是链表,仅输出元素即可
        print L[0]
    #处理L的其他部分
    printList(L[1:]) >>> aList=['a',['b','c',['d','e']],'f',[],'g']
>>> printList(aList)
a
b
c
d
e
f
g
>>> 由于上例中是列表的嵌套,所以我们必须测试首项是否为一个列表,如果是,则递归调用printList()函数,如果不是,那我们就简单地打印它。处理完首项后,我们将继续处理列表的其他各项。 在大型数据结构中,递归会耗尽内存,因此,如果你的内存比较小,或者想处理很大的数据结构,那么使用更复杂的常规代码可能更安全些。 2.Python有三种名字空间:     局部---在类,模块或方法中定义的名字     模块---在文件中定义的名字     内置---python自身定义的名字 如果要访问模块名字空间,使用import 3.事件驱动编程:面向批处理的程序流程是---启动程序,处理事情,然后终止程序;而事件驱动程序流程是---只有通过事件触发,程序才启动程序,等待事件,然后由事件通知它终止 编写事件驱动程序有两种方式:一是模拟一个事件环境;二是创建一个简单的GUI程序,该程序可利用操作系统和环境来生成事件。 事件捕获和处理的独立性是事件驱动编程的关键特性。


相关文档:

example of python operator overloadind

And last here is the overload operators example:
# map() takes two (or more) arguments, a function and a list to apply the function to
# lambda can be put anywhere a function is expected
# map() calls lambada for every element in the self list
# since Vector has overloaded __getitem__ and __len_ ......

python算法实践7 归并排序

def MergeSort(mylist, low, mid, high):
i = low
j = mid + 1
tmp = []

while i <= mid and j <= high:
if mylist[i] <= mylist[j]:
tmp.append(mylist[i])
i = i + 1
else:
tmp.append(mylist[j])
j = j + 1 ......

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号