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()

  • 相关阅读:
    A Simple PlugIn Library For .NET
    (转).NET 一次查询多表,填充DataSet并指定表名(DataSet指定DataTable名称的技巧)
    Database Schema Create
    C++中关于指针入门的最好的文章
    oleDbCommand访问Excel
    the best simple c++
    c++连接数据库
    plugin framework 1
    c# invoke c++
    摩根士丹利赐与新浪增持评级
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/6049311.html
Copyright © 2011-2022 走看看