>>> 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的更多相关文章

  1. Python File I/O

    File is a named location on disk to store related information. It is used to permanently store data ...

  2. Python - File - 第十八天

    Python File(文件) 方法 open() 方法 Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 OS ...

  3. [转]python file文件操作--内置对象open

    python file文件操作--内置对象open   说明: 1. 函数功能打开一个文件,返回一个文件读写对象,然后可以对文件进行相应读写操作. 2. file参数表示的需要打开文件的相对路径(当前 ...

  4. Python & file operation mode

    Python & file operation mode create/read/write/append mode https://docs.python.org/3/library/fun ...

  5. [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 ...

  6. python file operations

    原文地址 总是记不住API.昨晚写的时候用到了这些,但是没记住,于是就索性整理一下吧: python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当 ...

  7. python file 文件读写

    python 文本对象 继承自C的stdio包 打开 可以用内置的open()函数创建 with open("hello.txt") as f: for line in f: pr ...

  8. python file模块 替换输入内容脚本

    root@python-10:/home/liujianzuo/python/test# ls passwd rc.local test1 root@python-10:/home/liujianzu ...

  9. python file operation

    file.open(name[,mode[,buffering]]) 模式的类型有: r 默认只读 w     以写方式打开,如果文件不存在则会先创建,如果文件存在则先把文件内容清空(truncate ...

  10. python file文件操作--内置对象open

    说明: 1. 函数功能打开一个文件,返回一个文件读写对象,然后可以对文件进行相应读写操作. 2. file参数表示的需要打开文件的相对路径(当前工作目录)或者一个绝对路径,当传入路径不存在此文件会报错 ...

随机推荐

  1. C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 面向全国标准省市县行政数据基础之上的组织机构管理

    由于信息系统庞大.各种业务子系统.各种开发语言开发的业务逻辑.各种年代维护的代码.各种参差不齐的历史遗留信息系统,面向全国的业务系统,面向某个领域的汽运管理信息系统,面向内部的业务系统,面向外部的各种 ...

  2. moosefs的安装使用及遇到的问题

     一.获取源码安装包 到官网下载最新版本moosefs: https://moosefs.com/download/sources-archive-3-0.html到官网下载最新版本fuse源码 ht ...

  3. C#进阶系列——MEF实现设计上的“松耦合”(终结篇:面向接口编程)

    序:忙碌多事的八月带着些许的倦意早已步入尾声,金秋九月承载着抗战胜利70周年的喜庆扑面而来.没来得及任何准备,似乎也不需要任何准备,因为生活不需要太多将来时.每天忙着上班.加班.白加班,忘了去愤,忘了 ...

  4. C#进阶系列——DDD领域驱动设计初探(一):聚合

    前言:又有差不多半个月没写点什么了,感觉这样很对不起自己似的.今天看到一篇博文里面写道:越是忙人越有时间写博客.呵呵,似乎有点道理,博主为了证明自己也是忙人,这不就来学习下DDD这么一个听上去高大上的 ...

  5. Android开发之解决父控件拦截子控件事件问题

    以ViewPager为例: public class TopNewsViewPager extends ViewPager { public TopNewsViewPager(Context cont ...

  6. iOS开发小技巧--相机相册的正确打开方式

    iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...

  7. hdu3415 单调队列

    Max Sum of Max-K-sub-sequence Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  8. Configure Security Settings for Remote Desktop(RDP) Services Connections

    catalogue . Configure Server Authentication and Encryption Levels . Configure Network Level Authenti ...

  9. android 手机去哪儿7.2版本客户端 账号存储信息分析

    1.data/data/com.qunar sharepref 文件夹下的Qunarperferences.xml文件中 username,phone等均为加密处理过字段   2.jdgui下查找关键 ...

  10. c++ 虚函数

    class A { public: virtual void f();//希望派生类重写 void fun();//绝大多数情况下不要重新定义基类的非虚函数,那样会打破公有继承Is-A的关系,而且行为 ...