Python較之Perl在實際應(yīng)用中優(yōu)點所在
下面的文章是通過python寫的小程序源碼的相關(guān)代碼的示例來介紹Python編程語言在實際應(yīng)用的過程中操作方案,同時也用python和perl做一比較,突出前者在實際相關(guān)應(yīng)用方案的簡捷性。
閑的無聊就看了一點關(guān)于python的基礎(chǔ)知識,當(dāng)時也不知道python和perl之間爭論的這么的激烈(主要是當(dāng)時不知道perl這個語言的性質(zhì)),所以直接就看了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: ......
以上的代碼就是對我的第一個用python編程語言寫的小程序源碼的示例。
【編輯推薦】