添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Python语言基础
Python 教程 Python 简介 Python下载安装 Python 语法 Python 注释 Python 变量 Python 数据类型 Python 解释器 Python 运算符 Python 数字 Python 字符串 Python 布尔值 Python 列表 Python 元组 Python 数组 Python 集合 Python 字典 Python 分支 Python 循环 Python 函数 Python 作用域 Python 模块 Python 面向对象 Python 继承 Python 多态 Python 日期与时间 Python 内置函数 Python 迭代器 Python JSON Python XML Python File Python 实例 MySQL 日期/时间函数
Python语言进阶
Python 正则表达式 Python 多线程 Python 网络编程 Python 文档操作 Python 图形和游戏 Python CGI python 数据结构和算法 Python PyMySQL Python mysql-connector Python PostgreSQL Python SQLite Python mongodb Python redis Python 爬虫 Python lambda
Python数据结构
Python Maps Python 链表 Python 堆栈 Python 队列 Python 出队 Python 高级链接列表 Python 哈希表 Python 二叉树 Python 搜索树 Python 堆 Python 图 Python 算法设计 Python 分而治之 Python 递归 Python 回溯 Python Tree遍历 Python 排序算法 Python 搜索算法 Python 图算法 Python 算法分析 Python 算法类型 Python 算法类 readlines() 方法用于读取所有行(直到结束符 EOF)并返回列表,该列表可以由 Python 的 for... in ... 结构进行处理。 如果碰到结束符 EOF 则返回空字符串。 如果碰到结束符 EOF 则返回空字符串。 readlines() 方法语法如下: fileObject. readlines ( );
返回列表,包含所有的行。 以下实例演示了 readline() 方法的使用: 文件 lidihuo.txt 的内容如下: 1、www.lidihuo.com
2、www.lidihuo.com
3、www.lidihuo.com
4、www.lidihuo.com
5、www.lidihuo.com
循环读取文件的内容: # 打开文件
fo = open( "lidihuo.txt" , "r" )
print ( "文件名为: " , fo.name)
f or line in fo. readlines (): #依次读取每行
line = line. strip () #去掉每行头尾空白
print ( "读取的数据为: %s" % (line))
# 关闭文件
fo. close ()
以上实例输出结果为: 文件名为: lidihuo.txt
读取的数据为: 1、www.lidihuo.com
读取的数据为: 2、www.lidihuo.com
读取的数据为: 3、www.lidihuo.com
读取的数据为: 4、www.lidihuo.com
读取的数据为: 5、www.lidihuo.com