zoukankan      html  css  js  c++  java
  • python file

    复制代码

     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
    wozhidao
    xc4xb2xb0xd8xd0xf1
    '
    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
    wozhidao
    xc4xb2xb0xd8xd0xf1
    '
    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
    '
    59 >>> f.seek(0,0)
    60 >>> fw=open('E:\tmp.txt','w')
    61 >>> fw.write('let's go')
    62      
    63 SyntaxError: invalid syntax
    64 >>> fr=open('E:\tmp1.txt','w')
    65 >>> fr.write('nihao')
    66 >>> fr.close()
    复制代码
  • 相关阅读:
    android中src和background区别
    html标签大全
    android横竖屏切换时activity的生命周期
    onInterceptTouchEvent和onTouchEvent调用时序
    Android Activity单例
    Android dispatchTouchEvent
    android 2D API相关
    杭电 1085 Holding BinLaden Captive!
    杭电 1715 大菲波数
    杭电 1492 The number of divisors(约数) about Humble Numbers
  • 原文地址:https://www.cnblogs.com/wangsicongde/p/7599150.html
Copyright © 2011-2022 走看看