python file
>>> help(open)
Help on built-in function open in module __builtin__: open(...)
open(name[, mode[, buffering]]) -> file object Open a file using the file() type, returns a file object. This is the
preferred way to open a file. See file.__doc__ for further information. >>> f=open('E:\\tmp.txt')
>>> f
<open file 'E:\\tmp.txt', mode 'r' at 0x0000000002F84540>
>>> f.read()
'nihao\nwozhidao\n\xc4\xb2\xb0\xd8\xd0\xf1\n'
>>> list(f)
[]
>>> f.read(5)
''
>>> f.read()
''
>>> f=open("E:\\tmp.txt")
>>> f.read
<built-in method read of file object at 0x0000000002F845D0>
>>> f.read()
'nihao\nwozhidao\n\xc4\xb2\xb0\xd8\xd0\xf1\n'
>>> f.read()
''
>>> f=open("E:\\tmp.txt")
>>> f
<open file 'E:\\tmp.txt', mode 'r' at 0x0000000002F84540>
>>> f.read(5)
'nihao'
>>> f.seek() Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
f.seek()
TypeError: seek() takes at least 1 argument (0 given)
>>> f.tell()
5L
>>> lines=list(f)
>>> for eachLine in lines:
print eachLine wozhidao 牟柏旭 >>> f
<open file 'E:\\tmp.txt', mode 'r' at 0x0000000002F84540>
>>> f.read()
''
>>> f.seek(0,0)
>>> f.readline()
'nihao\n'
>>> f.seek(0,0)
>>> fw=open('E:\\tmp.txt','w')
>>> fw.write('let's go') SyntaxError: invalid syntax
>>> fr=open('E:\\tmp1.txt','w')
>>> fr.write('nihao')
>>> fr.close()

python file的更多相关文章
- Python File I/O
File is a named location on disk to store related information. It is used to permanently store data ...
- Python - File - 第十八天
Python File(文件) 方法 open() 方法 Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 OS ...
- [转]python file文件操作--内置对象open
python file文件操作--内置对象open 说明: 1. 函数功能打开一个文件,返回一个文件读写对象,然后可以对文件进行相应读写操作. 2. file参数表示的需要打开文件的相对路径(当前 ...
- Python & file operation mode
Python & file operation mode create/read/write/append mode https://docs.python.org/3/library/fun ...
- [python] File path and system path
1. get files in the current directory with the assum that the directory is like this: a .py |----dat ...
- python file operations
原文地址 总是记不住API.昨晚写的时候用到了这些,但是没记住,于是就索性整理一下吧: python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当 ...
- python file 文件读写
python 文本对象 继承自C的stdio包 打开 可以用内置的open()函数创建 with open("hello.txt") as f: for line in f: pr ...
- python file模块 替换输入内容脚本
root@python-10:/home/liujianzuo/python/test# ls passwd rc.local test1 root@python-10:/home/liujianzu ...
- python file operation
file.open(name[,mode[,buffering]]) 模式的类型有: r 默认只读 w 以写方式打开,如果文件不存在则会先创建,如果文件存在则先把文件内容清空(truncate ...
- python file文件操作--内置对象open
说明: 1. 函数功能打开一个文件,返回一个文件读写对象,然后可以对文件进行相应读写操作. 2. file参数表示的需要打开文件的相对路径(当前工作目录)或者一个绝对路径,当传入路径不存在此文件会报错 ...
随机推荐
- jquery修改css样式,样式带!important
由于需求的需要,今天在用jquery修改一个弹出框的样式的时候,由于有一个按钮有padding-left:12px;导致内间距空出来的这一块颜色用普通的方式无法改变. 普通的jquery修改css的方 ...
- K-means聚类算法
聚类分析(英语:Cluster analysis,亦称为群集分析) K-means也是聚类算法中最简单的一种了,但是里面包含的思想却是不一般.最早我使用并实现这个算法是在学习韩爷爷那本数据挖掘的书中, ...
- Pyhont-Urllib
urllib 方法 1 httpContent=urllib.urlopen(url) 2 fileName, httpContent= urllib.urlretrieve(url, filePat ...
- 江太公:javascript count(a)(b)(c)(d)运行过程思考
昨天,我弟抛给我一个js的题,使用类似标题那样的调用方法计算a*b*c*d以致无穷的实现方法.思考了半天,终于理清了它的运行过程,记录于下: 函数体: <!DOCTYPE html> &l ...
- iis虚拟目录名称“ReportServer”的巧合
今天测试一个Crystal Report网站的报表服务,建立一个虚拟目录,名为ReportServer,结果无论怎样访问浏览器都返回 localhost/ReportServer - / Micr ...
- check fasta format
reference: https://www.biostars.org/p/42126/ fasta.y %{ #include <stdio.h> #include <stdlib ...
- wpf converter converterparameter 绑定多参数
1. converterparameter不是依赖属性,所以不能用binding. 2. 可以把converter 的接口 IValueConverter改为 IMultiValueConverter ...
- JBoss 系列十四:JBoss7/WildFly如何加载外部的文件或properties文件
http://www.tuicool.com/articles/M7ZR3y 原文 http://blog.csdn.net/kylinsoong/article/details/12623997 主 ...
- BZOJ3172: [Tjoi2013]单词
传送门 做了这么多题怎么还是无法很好的理解AC自动机呢..果然是个制杖 首先题意表述不是很清晰,这些所有的单词组成了那个文章,所以果断建个AC自动机,建的时候给每个点附加一个权值,建树是经过一次权值即 ...
- CSS DIV自动适应高度
当div需要设定自适应高度时,可用到的css属性,min-height:200px;代表的是当div的内容超出了200px时,就会自动适应高度,兼容所有浏览器(IE6除外),如果是IE6则需要设置&q ...
