输入文件名-如果文件存在-读文件内容(Python)

来源:互联网 发布:网络访问安全设计 编辑:程序博客网 时间:2024/05/29 07:59



def readTextFile():    fname=input("输入文件名:")    print()    try:        fobj=open(fname,'r')    except IOError as e:        print("***file open error:",e)    else:        for eachLine in fobj:            print(eachLine,end='')        fobj.close()

运行结果:

>>> readTextFile()输入文件名:Hell.txt你好呀你好细细


阅读全文
0 0
原创粉丝点击