zoukankan      html  css  js  c++  java
  • 《Python核心编程》部分错误纠正(勘误表)(持续更新)

    Chapter 3:

    例3-1 makeTextFile.py

    #!/usr/bin/env python
    
    'makeTextFile.py'
    import os
    ls = os.linesep
    
    #get File name
    
    while True:
        fname = raw_input("Enter file name: ")
        if os.path.exists(fname):
            print "ERROR: '%s' already exists" % fname
        else:
            break
    
    #get file contents lines
    
    all = []
    print "
    Enter lines('.' by itself to quit).
    "
    
    #loop until user terminate 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.write('
    ',join(all))
    fobj.close()
    print "DONE"
    View Code

    例3-2 readTextFile.py

    #!/usr/bin/env python
    
    'readTextFile.py'
    #get filename
    fname = raw_input('Enter filename: ')
    print
    
    #attempt to open file for reading
    try:
        fobj = open(fname,'r')
    except IOError, e:
        print "*** file open error:", e
    else:
        #display contents to the screen
        for eachLine in fobj:
            print eachLine,
    
    fobj.close()
    View Code
  • 相关阅读:
    sql时间天数操作
    SQL死锁
    sql操作数据库结构
    sql设置时间显示格式
    sql树形结果,查询所有子类
    centos6.5 mysql 安装
    windows git 使用
    centos6.5 vsftpd的搭建
    centos 6.5 Nginx安装
    jQuery源码中的Ajax--load方法
  • 原文地址:https://www.cnblogs.com/whatbeg/p/3661616.html
Copyright © 2011-2022 走看看