• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > 在Python中操作文件之read()方法的使用教程

在Python中操作文件之read()方法的使用教程

作者:goldensun 字体:[增加 减小] 来源:互联网

goldensun 通过本文主要向大家介绍了python read,python read函数,python read excel,python read table,python file read等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

 read()方法读取文件size个字节大小。如果读取命中获得EOF大小字节之前,那么它只能读取可用的字节。
语法

以下是read()方法的语法:

fileObject.read( size );

</div>

参数

  •     size -- 这是可以从文件中读取的字节数。

返回值

此方法返回读取字符串中的字节数。
例子

下面的例子显示了read()方法的使用。

#!/usr/bin/python

# Open a file
fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name

# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line

line = fo.read(10)
print "Read Line: %s" % (line)

# Close opend file
fo.close()

</div>

当我们运行上面的程序,它会产生以下结果:

Name of the file: foo.txt
Read Line: This is 1s

</div>

</div>

您可能想查找下面的文章:

  • 简单介绍Python中的readline()方法的使用
  • 在Python中操作文件之read()方法的使用教程
  • python中readline判断文件读取结束的方法

相关文章

  • python实现简单温度转换的方法
  • Python编程中字符串和列表的基本知识讲解
  • 详解Python中的相对导入和绝对导入
  • Python实现将xml导入至excel
  • python批量同步web服务器代码核心程序
  • Python写的英文字符大小写转换代码示例
  • python实现同时给多个变量赋值的方法
  • Python实现的RSS阅读器实例
  • Python中的复制操作及copy模块中的浅拷贝与深拷贝方法
  • python3使用urllib示例取googletranslate(谷歌翻译)

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python+Wordpress制作小说站
    • 浅谈Python单向链表的实现
    • Python中使用插入排序算法的简单分析与代码示例
    • 深入解析Python中函数的参数与作用域
    • python使用clear方法清除字典内全部数据实例
    • python基础教程之五种数据类型详解
    • Python获取运行目录与当前脚本目录的方法
    • Python urllib模块urlopen()与urlretrieve()详解
    • Python 的内置字符串方法小结
    • Django中使用locals()函数的技巧

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有