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

Python文件操作类操作实例详解

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

shichen2014 通过本文主要向大家介绍了python开发技术详解,python os模块详解,python正则表达式详解,python 字典详解,python类详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文讲述了Python文件操作类的操作实例,详细代码如下:

#!/usr/bin/env python
#!/usr/bin/env python 
#coding:utf-8 
# Purpose: 文件操作类

#声明一个字符串文本 
poem=''' 
Programming is fun测试 
When the work is done 
if you wanna make your work also fun: 
use Python! 
''' 
#创建一个file类的实例,模式可以为:只读模式('r')、写模式('w')、追加模式('a') 
f=file('poem.txt','a') #open for 'w'riting 
f.write(poem) #写入文本到文件 write text to file 
f.close() #关闭文件 close the file

#默认是只读模式 
f=file('poem.txt') 
# if no mode is specified,'r'ead mode is assumed by default 
while True: 
line=f.readline() #读取文件的每一个行 
if len(line)==0: # Zero length indicates EOF 
break 
print line, #输出该行 
#注意,因为从文件读到的内容已经以换行符结尾,所以我们在输出的语句上使用逗号来消除自动换行。 
 
#Notice comma to avoid automatic newline added by Python 
f.close() #close the file

#帮助 
help(file)
</div> </div>

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

  • python中OrderedDict的使用方法详解
  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • Python 操作MySQL详解及实例
  • python中OrderedDict的使用方法详解
  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • Python 操作MySQL详解及实例
  • Python 登录网站详解及实例
  • 详解Python中类的定义与使用

相关文章

  • Windows下Python的Django框架环境部署及应用编写入门
  • python发送HTTP请求的方法小结
  • Django Admin实现上传图片校验功能
  • Python实现二叉搜索树
  • Python的Django框架中的URL配置与松耦合
  • Python实现的简单算术游戏实例
  • 深入解析Python中的线程同步方法
  • python编写暴力破解FTP密码小工具
  • python数据结构之二叉树的遍历实例
  • Python Socket编程入门教程

文章分类

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

最近更新的内容

    • python实现登陆知乎获得个人收藏并保存为word文件
    • Python3基础之基本数据类型概述
    • Python实现统计英文单词个数及字符串分割代码
    • Python魔术方法详解
    • 在Python中使用异步Socket编程性能测试
    • python对数组进行反转的方法
    • 浅析Python中MySQLdb的事务处理功能
    • python简单读取大文件的方法
    • 在Python的Django框架中调用方法和处理无效变量
    • python原始套接字编程示例分享

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

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