python学习日记(二)

创建自己的库函数

创建自己的库函数需要两个文件

功能函数文件 例如 testprint2.py 还有个就是setup.py

setup.py中包含的内容:

from distutils.core import setup
setup(
        name = 'test2',
        version = '1.0.0',
        py_modules = ['testprint2'],#这里必须填写要编译的文件的名字,不然会报错
        author = 'zj',
        author_email = 'XXXX@XXX.XX',
        url = 'http://XXX.XXX.com',
        description = 'just a test !',
    )

  

然后吧这两个文件装载一个文件夹中,名字随意。例如test2.

在windows,的dos窗口中将路径转到test2所在目录下。

输入setup.py sdist

在输入:setup.py install

自己的库就写好了!

例如本程序中testprint2.py中的内容为:

def printMessage():
    print("this just a test 2 !")

  

则在其他文件中引入该包调用print

import testprint2

testprint2.printMessage()

可以得到this just a test 2 !

 

练习:

 1 def lop(the_list ,ident = False ,level = 0):
 2     for item in the_list:
 3         if isinstance (item,list):
 4             lop(item,ident,level+1)
 5         else:
 6             if ident:
 7                 for num in range(level):
 8                      print("\t",end = '')
 9             print(item)
10 
11 letters = ['a','v','b','e','u',['r','f','t',],'p',['e','h','k']]
12 
13 lop(letters,True,1)

在python中如果要声明boolean则True和False的首字母要大写。

posted @ 2013-05-11 16:36  拙急鸟  阅读(194)  评论(0编辑  收藏  举报