Recently bought online this Python core programming (second edition) Chinese version, just read a few chapters, on the machine practice a few procedures, found that printing problems, do not know what the reason. Online search, found that other netizens also found similar problems. Here I have encountered the problem of the program posted to record their own learning process.
52nd Page Program Example maketextfile.py
#!/usr/bin/python ' Maketextfile.py -- create text file ' import osls = Os.linesep# get filenamewhile true: fname = raw_input (' Enter filename: ') if os.path.exists (fname): print "error: '%s ' already exists" % fname else: break# get file content (text) linesall = []print "\nenter lines ('. ') by itself to quit). \ n "# loop until user terminates inputswhile true: entry = raw_input (' > ') if entry == '. ': break else: all.append (Entry) # wriTe lines to file with proper line-endingfobj = open (fname, ' W ') Fobj.writelines (['%s%s ' % (x, ls) for x in all]) fobj.close () print ' done! '
This article is from the "Tiandaochouqin" blog, make sure to keep this source http://lavenliu.blog.51cto.com/5060944/1564093
Python Core Programming (second edition) Errata