码迷,mamicode.com
首页 > 编程语言 > 详细

python file

时间:2016-11-10 02:57:21      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:ref   return   let   write   ati   inf   nihao   back   nbsp   

技术分享

 

 1 >>> help(open)
 2 Help on built-in function open in module __builtin__:
 3 
 4 open(...)
 5     open(name[, mode[, buffering]]) -> file object
 6     
 7     Open a file using the file() type, returns a file object.  This is the
 8     preferred way to open a file.  See file.__doc__ for further information.
 9 
10 >>> f=open(E:\\tmp.txt)
11 >>> f
12 <open file E:\\tmp.txt, mode r at 0x0000000002F84540>
13 >>> f.read()
14 nihao\nwozhidao\n\xc4\xb2\xb0\xd8\xd0\xf1\n
15 >>> list(f)
16 []
17 >>> f.read(5)
18 ‘‘
19 >>> f.read()
20 ‘‘
21 >>> f=open("E:\\tmp.txt")
22 >>> f.read
23 <built-in method read of file object at 0x0000000002F845D0>
24 >>> f.read()
25 nihao\nwozhidao\n\xc4\xb2\xb0\xd8\xd0\xf1\n
26 >>> f.read()
27 ‘‘
28 >>> f=open("E:\\tmp.txt")
29 >>> f
30 <open file E:\\tmp.txt, mode r at 0x0000000002F84540>
31 >>> f.read(5)
32 nihao
33 >>> f.seek()
34 
35 Traceback (most recent call last):
36   File "<pyshell#14>", line 1, in <module>
37     f.seek()
38 TypeError: seek() takes at least 1 argument (0 given)
39 >>> f.tell()
40 5L
41 >>> lines=list(f)
42 >>> for eachLine in lines:
43     print eachLine
44 
45     
46 
47 
48 wozhidao
49 
50 牟柏旭
51 
52 >>> f
53 <open file E:\\tmp.txt, mode r at 0x0000000002F84540>
54 >>> f.read()
55 ‘‘
56 >>> f.seek(0,0)
57 >>> f.readline()
58 nihao\n
59 >>> f.seek(0,0)
60 >>> fw=open(E:\\tmp.txt,w)
61 >>> fw.write(lets go)
62      
63 SyntaxError: invalid syntax
64 >>> fr=open(E:\\tmp1.txt,w)
65 >>> fr.write(nihao)
66 >>> fr.close()

技术分享

 

python file

标签:ref   return   let   write   ati   inf   nihao   back   nbsp   

原文地址:http://www.cnblogs.com/13224ACMer/p/6049311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!