>>> 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. 通过trie树实现单词自动补全

    /** * 实现单词补全功能 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #incl ...

  2. sublime text nodejs set

    把新建的system清空,输入{ "cmd": ["node", "$file"], "selector": " ...

  3. 关于SIGSEGV错误及处理方法(转)

    转自:http://blog.csdn.net/brace/article/details/1102422   今天编程遇到了SIGSEGV错误,比较困惑,所以找了些资料,总结一下: (1)官方说法是 ...

  4. nodejs express 静态文件的路径

    当express 设置为静态文件服务器的时候.可以通过2种方式进行方位: 1,通过设置app.use('路径1','../a/b/image') express 路径的形式,如 src="路 ...

  5. shell脚本每天自动备份mysql数据库

    一.mysql提供了一个mysqldump的工具可以方便的导出导入数据库信息: 二.使用命令行shell测试执行mysqldump,理解必备的参数,查看生成的sql备份文件是否符合需求: /usr/b ...

  6. js在手机端不能正确显示

    在html页面head中加入<meta name="viewport" content="width=device-width, initial-scale=1.0 ...

  7. 用JS写了一个打字游戏,反正我是通不了关

    今天想写个简单的游戏, 打字游戏好像都没写过, 那么就写打字游戏吧, gamePad包含了关卡的信息, 可以用来调整给个关卡字符下落的速度: getRandom函数会返回一个字符对象, 这个对象包含了 ...

  8. 线段树 HDU 3308

    t 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y   2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 #include< ...

  9. TCP协议中的三次握手和四次挥手(图解)

    建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看如何建立连接的. 首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资 ...

  10. STM32库函数编程、Keli/MDK、stm32f103zet6

    catalogue . Cortex-M3地址空间 . 基于标准外设库的软件开发 . 基于固件库实现串口输出(发送)程序 . 红外接收实验 . 深入分析流水灯例程 . GPIO再举例之按键实验 . 串 ...