啄木鸟,python讲座,源码_part3

啄木鸟,python讲座,源码_part3


#************************************************


d1 = range(10)
while d1:
      print d1.pop(),

print "\n---- next 1 ----"
for i in range(9,-1,-1):
    print i,

print "\n---- next 2 ----"

def g():
    d2 = range(10)
    while d2:
          yield d2.pop()

d2 = g()

for i in d2:
    print i,

print "\n---- next 3 ----"

# 异常.
d3 = g()

while True:
      try:
          print d3.next(),
      except StopIteration:
                 break

print "\n---- lambda ----"
# 匿名函数.
print "map(str,range(10)) = ", map(str,range(10))


from random import random as _random

print [i for i in range(10) if i>5]

print filter(lambda x: x > 0.5 and x, [_random() for i in range(10)])

def e():
    r = raw_input('please input : ')
    print eval(r)

e()


#**************************************************
# 自省能力.
# type
# dir
# traceback
#**************************************************
print 'type("hello") = ', type("hello")
print 'type(1) = ', type(1)
print 'type(type) = ', type(type)
print 'type(lambda:1) = ', type(lambda:1)
print 'dir() = ', dir()

from traceback import extract_stack
def fn_a():
    fn_b()

def fn_b():
    fname = extract_stack()[-2][2]
    print 'caller : ', fname
    print eval(fname)

fn_a()

#**************************************************
# 网络应用.
# Twisted
# libgmail
# MoinMoin---wiki.

# 文本处理.
# elementtree
# 4suite

# 图形用户界面(GUI)
# TK python
# wxPython
# pyQT

# 数据库
# pySqlite
# pymssql
# pyPgSql

# 多媒体
# PySonic,fmod
# PyMedia

# 开发工具
# pyUnit
# py2exe
# pyGame

# 国外成功应用
# Google
# Disney.

# 国内项目
# douban
# WeKnow
#**************************************************

















你可能感兴趣的:(啄木鸟,python讲座,源码_part3)