第一个python小程序
闲的无聊就看了一点关于python的基础知识,当时也不知道python和perl之间争论的这么的激烈(主要是当时不知道perl这个语言的性质),所以直接就看了python,下面是我的第一个用python写的小程序源码,希望朋友们多多指教,有什么问题大家尽管指正,在此先谢谢大家了。
[code]
#!/usr/bin/python
import sys, os, re
import pickle as p
class address:
def __init__(self,name,email,telephone):
self.name = name
self.email = email
self.telephone = telephone
def edit(self,new_name,new_email,new_telephone):
if len(new_name) != 0:
self.name = new_name
if len(new_email) != 0:
self.email = new_email
if len(new_telephone) != 0:
self.telephone = new_telephone
if os.path.exists('address.data'):
f = file('address.data')
d_book = p.load(f)
else:
d_book = {}
#print the menu
def printmenu():
print '-----------------'
print '''1.append
2.edit
3.delete
4.find
5.exit
6.print '''
print '-----------------'
s = raw_input('please input your choice(1-6):')
return s
while True:
ans_ = printmenu()
if ans_ == '1':
print 'you will append an item.'
name = raw_input ('please input name:')
if name in d_book:
print '%s exists, please append a new one.' % name
else:
相关文档:
David 在本文中将带领我们了解一下 setuptools 框架,它是 Python Enterprise Application Kit(PEAK)的一个副项目。 setuptools 替换了标准的 distutils 库,并为 Python 添加了版本化的包和依赖性管理。Perl 用户比较熟悉 CPAN,而 Ruby 用户则比较熟悉 Gems;引导 setuptools 的 ez_setup 工具和随之而生的扩展后的 eas ......
python的egg文件有点像java中的jar文件,是一个工程打包文件,便于安装部署,仅此一点,给多少pythoner带来了多少激动。
如何制作egg文件呢?see官方文档http://peak.telecommunity.com/DevCenter/PythonEggs,
到http://pypi.python.org/pypi/setuptools下载setuptools包,然后安装:
python setup.py
1.制作egg文件
......
PLY模块 是Lex/YACCPython 的实现,可以用来实现词法分析/语法分析,但如何用,还没研究,以后有时间再研究吧;
主页: http://www.dabeaz.com/ply/
pycparser模块 是使用PLY模块分析c语言语法的模块,没什么文档,但模块自带了例子和测试用例。
主页: http://code.google.com/p/pycpa ......
1 在想要插入断点的地方插入代码
import pdb
pdb.set_trace()
2然后使用指令进行debug
查看代码上下文,l(小写L)
监视变量 ......