新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Pythonforin實(shí)際應(yīng)用代碼操作方法
Python編程語(yǔ)言一經(jīng)推出就憑借其簡(jiǎn)單易用這一特點(diǎn)極大的吸引了開(kāi)發(fā)人員的注意。那么它的到來(lái)究竟給我們的編程方式帶來(lái)了哪些改變呢?我們今天就來(lái)從Python for in的應(yīng)用方法來(lái)體驗(yàn)這種變化。

Python for in代碼示例:
- #!/usr/bin/env python
- 'makeTextFile.py -- create text file'
- import os
- ls = os.linesep
- # get filename
- while True:
- if os.path.exists(fname):
- print"*** ERROR: '%s' already exists" % fname
- else:
- break
- # get file content (text) lines
- all = []
- print "\nEnter lines ('.' by itself to quit).\n"
- # loop until user terminates input
- while True:
- entry = raw_input('> ')
- if entry == '.':
- break
- else:
- all.append(entry)
- # write lines to file with proper line-ending
- fobj = open(fname, 'w')
- fobj.writelines(['%s%s' % (x, ls) for x in all])
- fobj.close()
- print 'DONE!'
希望這里介紹的Python for in的實(shí)際應(yīng)用示例能給大家在學(xué)習(xí)中帶來(lái)些幫助。
新聞名稱:Pythonforin實(shí)際應(yīng)用代碼操作方法
網(wǎng)頁(yè)鏈接:http://m.fisionsoft.com.cn/article/cccpdhg.html


咨詢
建站咨詢
