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

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的實際應用示例能給大家在學習中帶來些幫助。
分享標題:Pythonforin實際應用代碼操作方法
網(wǎng)站路徑:http://www.5511xx.com/article/cccpdhg.html


咨詢
建站咨詢
