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参数表示的需要打开文件的相对路径(当前工作目录)或者一个绝对路径,当传入路径不存在此文件会报错 ...
随机推荐
- JSHint配置项说明
转自:http://www.jianshu.com/p/4cb23f9e19d3 什么是JSHint? 官方网站这样介绍: JSHint, A Static Code Analysis Tool fo ...
- B树、B-树、B+树、B*树
B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right) 2.所有结点存储一个关键字 3.非叶子节点的左指针指向小于其关键字的字数,右指针指向大于其关键字的字数: 如: B树的 ...
- React-Router学习整理
欢迎大家指导与讨论 : ) 一.前言 本文摘要:react-router的基本用法,动画效果与路由,路由权限控制,路由离开确认,根据路由切分的按需加载,路由组件的属性.本文是笔者在学习时整理的笔记,由 ...
- TCP/IP协议中网关和子网掩码概念
网关: 不同网段的IP是不能直接互通的,需要一个设备来转发,这个设备就是网关,一般就是路由器,那么路由器的地址就是网关地址. 比如192.168.2.31要往192.168.3.31发送一条消息,他们 ...
- ASM, AAM
名称 下载网址 am_tools http://www.isbe.man.ac.uk/~bim/software/am_tools_doc/index.html VOSM http://sourcef ...
- JavaScript模板引擎artTemplate.js——两种方法实现性别的判定
template.helper(name, callback) name:必传,辅助事件的名称. callback:必传,辅助事件的回调函数. return:undefined 所谓的辅助事件,主要用 ...
- 【抓包工具】wireshark
wireshark下载地址:http://download.csdn.net/detail/victoria_vicky/8819777 一.wireshark优劣势 wireshark劣势:只能查看 ...
- jsonp接口的xss防范
防范方式也很简单,只要在header里输出类型设置为javascript即可: 1 header('Content-type: text/javascript;charset=utf-8');
- redis-windows执行redis-cli查询
1.无密码时的访问 redis-cli -h redis > redis > keys *1) "myset"2) "mysortset" redi ...
- log4j配置文件加载
log4j的jar包内部包含preference默认配置,使用者可以通过log4j.xml或log4j.properties来指定自己的配置.xml比properties优先.另外注意java读取pr ...
