首页 > 编程语言 > 详细

Python 文件编码

时间:2015-11-09 18:43:23      阅读:246      评论:0      收藏:0      [点我收藏+]

发到哈工大

 

 

打开文件:

建立磁盘上的文件与程序中的对象相关联

通过相关的文件对象获得

 

读取

写入

定位

其他:追加,计算等

 

关闭文件

切断文件与程序的联系

写入磁盘,并释放文件缓冲区

 

打开文件:

open()

<variable> = open (<name>,<mode>)

<name>磁盘文件名

<mode>打开模式

技术分享

egg:

打开一个名为“numbers.dat”的文本文件

>>>infile =  open ("numbers.dat","r")

打开一个名为“music.mp3”的音频文件

>>>infile = open("music.mp3","rb")

技术分享

def main()"
  fname = input ("Enter filename:")

  infile = open(fname,"r")

  data = infile.read()

  print(data)

main()

 

infile = open(someFile,"r")

for i in range(5):

  line = infile.readline()

  print(line[:-1])

 

技术分享

>>>outfile = open("outfile.txt","w")

>>>outfile .writelines(["Hello"," ","world"])

>>>outfile.close()

>>>infile = open("outfile.txt","r")

>>>infile.read()

‘Hello world‘

技术分享

技术分享

技术分享

 

python 读文件中的数字利用turtle画图

http://www.icourse163.org/learn/bit-268001?tid=317001#/learn/content?type=detail&id=872018&sm=1

 

Python 文件编码

原文:http://www.cnblogs.com/XDJjy/p/4950521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!