Python 之 读取txt文件
2015-08-16 14:23
609 查看
本文直接给出三种实现方法,代码如下。
方法一:
方法二:
方法三:
方法一:
f = open("Proc_Data.txt") # 返回一个文件对象 line = f.readline() # 调用文件的 readline()方法 while line: print line, # 后面跟 ',' 将忽略换行符 # print(line, end = '') # 在 Python 3中使用 line = f.readline() f.close()
方法二:
for line in open("Proc_Data.txt"): print line,
方法三:
f = open("F:\\wfpdm\\My_Proc_Data_ZXTZ.txt","r") lines = f.readlines()#读取全部内容 for line in lines print line
相关文章推荐
- py 格式转换为 exe 使用方法
- Python包管理工具-pip
- win 环境安装python 和 Py pip
- [python leetcode] Word Ladder II (very hard)[非常难,放弃]
- PAT 01-2. Maximum Subsequence Sum (25) - Python
- python选择排序实现法
- python2.7虚拟环境virtualenv安装及使用
- python-requests快速上手
- wxPython Cookbook (Chatper1)part 4
- python快速排序法实现
- Python初学(1)
- Python中的random模块
- PAT 01-1. 最大子列和问题(20)-Python
- 取石子游戏
- Python编程习惯
- Python3.4 Python的一些特色
- Python2.7 安装numpy报错解决方法
- 6个最佳的开源 Python 应用服务器
- vijos - P1279Leave-绿光(数学归纳法 + python)
- Python快速教程