oct()open()20181015

oct()open()20181015.md

def oct(*args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
    """
    Return the octal representation of an integer.
    
       >>> oct(342391)
       '0o1234567'
    """
    pass
    remark = '''备注:将10进制的整数转化成8进制,bin():10到2进制: 0b开头
                                            oct():10到8进制: 0o开头
                                            hex():10到16进制:0x开头
                                            '''

'代码难证:'
>>> hex(22)
'0x16'
>>> oct(22)
'0o26'
>>> bin(22)
'0b10110'



def open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=True): # known special case of open
    """
    Open file and return a stream.  Raise OSError upon failure.
    
    file is either a text or byte string giving the name (and the path
    if the file isn't in the current working directory) of the file to
    be opened or an integer file descriptor of the file to be
    wrapped. (If a file descriptor is given, it is closed when the
    returned I/O object is closed, unless closefd is set to False.)
    
    mode is an optional string that specifies the mode in which the file
    is opened. It defaults to 'r' which means open for reading in text
    mode.  Other common values are 'w' for writing (truncating the file if
    it already exists), 'x' for creating and writing to a new file, and
    'a' for appending (which on some Unix systems, means that all writes
    append to the end of the file regardless of the current seek position).
    In text mode, if encoding is not specified the encoding used is platform
    dependent: locale.getpreferredencoding(False) is called to get the
    current locale encoding. (For reading and writing raw bytes use binary
    mode and leave encoding unspecified.) The available modes are:
    
    ========= ===============================================================
    Character Meaning
    --------- ---------------------------------------------------------------
    'r'       open for reading (default)
    'w'       open for writing, truncating the file first
    'x'       create a new file and open it for writing
    'a'       open for writing, appending to the end of the file if it exists
    'b'       binary mode
    't'       text mode (default)
    '+'       open a disk file for updating (reading and writing)
    'U'       universal newline mode (deprecated)
    ========= ===============================================================
    
    The default mode is 'rt' (open for reading text). For binary random
    access, the mode 'w+b' opens and truncates the file to 0 bytes, while
    'r+b' opens the file without truncation. The 'x' mode implies 'w' and
    raises an `FileExistsError` if the file already exists.
    
    Python distinguishes【】 between files opened in binary and text modes,
    even when the underlying operating system doesn't. Files opened in
    binary mode (appending 'b' to the mode argument) return contents as
    bytes objects without any decoding. In text mode (the default, or when
    't' is appended to the mode argument), the contents of the file are
    returned as strings, the bytes having been first decoded using a
    platform-dependent encoding or using the specified encoding if given.
    
    'U' mode is deprecated and will raise an exception in future versions
    of Python.  It has no effect in Python 3.  Use newline to control
    universal newlines mode.
    
    buffering is an optional integer used to set the buffering policy.
    Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
    line buffering (only usable in text mode), and an integer > 1 to indicate
    the size of a fixed-size chunk buffer.  When no buffering argument is
    given, the default buffering policy works as follows:
    
    * Binary files are buffered in fixed-size chunks; the size of the buffer
      is chosen using a heuristic trying to determine the underlying device's
      "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
      On many systems, the buffer will typically be 4096 or 8192 bytes long.
    
    * "Interactive" text files (files for which isatty() returns True)
      use line buffering.  Other text files use the policy described above
      for binary files.
    
    encoding is the name of the encoding used to decode or encode the
    file. This should only be used in text mode. The default encoding is
    platform dependent, but any encoding supported by Python can be
    passed.  See the codecs module for the list of supported encodings.
    
    errors is an optional string that specifies how encoding errors are to
    be handled---this argument should not be used in binary mode. Pass
    'strict' to raise a ValueError exception if there is an encoding error
    (the default of None has the same effect), or pass 'ignore' to ignore
    errors. (Note that ignoring encoding errors can lead to data loss.)
    See the documentation for codecs.register or run 'help(codecs.Codec)'
    for a list of the permitted encoding error strings.
    
    newline controls how universal newlines works (it only applies to text
    mode). It can be None, '', '\n', '\r', and '\r\n'.  It works as
    follows:
    
    * On input, if newline is None, universal newlines mode is
      enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
      these are translated into '\n' before being returned to the
      caller. If it is '', universal newline mode is enabled, but line
      endings are returned to the caller untranslated. If it has any of
      the other legal values, input lines are only terminated by the given
      string, and the line ending is returned to the caller untranslated.
    
    * On output, if newline is None, any '\n' characters written are
      translated to the system default line separator, os.linesep. If
      newline is '' or '\n', no translation takes place. If newline is any
      of the other legal values, any '\n' characters written are translated
      to the given string.
    
    If closefd is False, the underlying file descriptor will be kept open
    when the file is closed. This does not work when a file name is given
    and must be True in that case.
    
    A custom opener can be used by passing a callable as *opener*. The
    underlying file descriptor for the file object is then obtained by
    calling *opener* with (*file*, *flags*). *opener* must return an open
    file descriptor (passing os.open as *opener* results in functionality
    similar to passing None).
    
    open() returns a file object whose type depends on the mode, and
    through which the standard file operations such as reading and writing
    are performed. When open() is used to open a file in a text mode ('w',
    'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open
    a file in a binary mode, the returned class varies: in read binary
    mode, it returns a BufferedReader; in write binary and append binary
    modes, it returns a BufferedWriter, and in read/write mode, it returns
    a BufferedRandom.
    
    It is also possible to use a string or bytearray as a file for both
    reading and writing. For strings StringIO can be used like a file
    opened in a text mode, and for bytes a BytesIO can be used like a file
    opened in a binary mode.
    """
    pass
     baidu_translate = '''
    Open file and return a stream. Raise OSError upon failure.

    打开文件并返回流。失败时提高误差。



    file is either a text or byte string giving the name (and the path

    文件是提供名称的文本或字节字符串(以及路径)

    if the file isn't in the current working directory) of the file to

    如果文件不在文件的当前工作目录中

    be opened or an integer file descriptor of the file to be

    被打开或是文件的整数文件描述符

    wrapped. (If a file descriptor is given, it is closed when the

    包裹。(如果给出了文件描述符,则在

    returned I/O object is closed, unless closefd is set to False.)

    返回的I/O对象是关闭的,除非关闭EFED设置为false。



    mode is an optional string that specifies the mode in which the file

    模式是一个可选字符串,它指定文件的模式

    is opened. It defaults to 'r' which means open for reading in text

    打开。它默认为“R”,这意味着在文本中阅读是开放的。

    mode. Other common values are 'w' for writing (truncating the file if

    模式。其他常用的值是“W”用于写入(截断文件)

    it already exists), 'x' for creating and writing to a new file, and

    它已经存在,用于创建和写入新文件的“X”,以及

    'a' for appending (which on some Unix systems, means that all writes

    “A”用于附加(在某些UNIX系统上),意味着所有的写入

    append to the end of the file regardless of the current seek position).

    追加到文件的末尾,不管当前的查找位置。

    In text mode, if encoding is not specified the encoding used is platform

    在文本模式下,如果未指定编码,则使用的编码是平台。

    dependent: locale.getpreferredencoding(False) is called to get the

    依赖:LoaLa.GETApple RealEngDebug(FALSE)被调用以获得

    current locale encoding. (For reading and writing raw bytes use binary

    当前区域设置编码。(用于读取和写入原始字节使用二进制)

    mode and leave encoding unspecified.) The available modes are:

    模式和离开编码未指定。)可用模式是:



    ========= ===============================================================

    事业单位

    Character Meaning

    字义

    --------- ---------------------------------------------------------------

    ----------------------------------------

    'r' open for reading (default)

    “打开”用于阅读(默认)

    'w' open for writing, truncating the file first

    “W”打开写入,首先截断文件

    'x' create a new file and open it for writing

    “X”创建一个新文件并打开它进行写入

    'a' open for writing, appending to the end of the file if it exists

    “a”打开写入,如果文件存在,则追加到文件的末尾

    'b' binary mode

    “B”二进制模式

    't' text mode (default)

    “T”文本模式(默认)

    '+' open a disk file for updating (reading and writing)

    “+”打开一个磁盘文件进行更新(读写)

    'U' universal newline mode (deprecated)

    “U”通用换行方式(弃用)

    ========= ===============================================================

    事业单位



    The default mode is 'rt' (open for reading text). For binary random

    默认模式是“RT”(用于读取文本的打开)。二进制随机

    access, the mode 'w+b' opens and truncates the file to 0 bytes, while

    Access中,“W+B”模式打开并截断文件到0字节,而

    'r+b' opens the file without truncation. The 'x' mode implies 'w' and

    “R+B”打开文件而不截断。“X”模式意味着“W”和

    raises an `FileExistsError` if the file already exists.

    如果文件已经存在,则引发“文件生存”。



    Python distinguishes【】 between files opened in binary and text modes,

    Python在二进制和文本模式下打开的文件之间区别开来,

    even when the underlying operating system doesn't. Files opened in

    甚至当底层操作系统也没有。

    binary mode (appending 'b' to the mode argument) return contents as

    二进制模式(追加'b'到模式参数)返回内容为

    bytes objects without any decoding. In text mode (the default, or when

    没有任何解码的字节对象。在文本模式(默认模式下)

    't' is appended to the mode argument), the contents of the file are

    “T”被附加到模式参数中,文件的内容是

    returned as strings, the bytes having been first decoded using a

    返回为字符串,字节已被首次解码使用

    platform-dependent encoding or using the specified encoding if given.

    依赖于平台的编码,或者如果给定的话使用指定的编码。



    'U' mode is deprecated and will raise an exception in future versions

    “U”模式被弃用,将在将来版本中引发异常。

    of Python. It has no effect in Python 3. Use newline to control

    蟒蛇。它在Python 3中没有作用。使用换行控制

    universal newlines mode.

    通用换行模式。



    buffering is an optional integer used to set the buffering policy.

    缓冲是一个可选的整数,用于设置缓冲策略。

    Pass 0 to switch buffering off (only allowed in binary mode), 1 to select

    通过0切换缓冲(仅允许二进制模式),1选择

    line buffering (only usable in text mode), and an integer > 1 to indicate

    行缓冲(仅在文本模式下可用)和整数>1指示

    the size of a fixed-size chunk buffer. When no buffering argument is

    一个固定大小的块缓冲区的大小。当没有缓冲参数时

    given, the default buffering policy works as follows:

    给定的,默认缓冲策略的工作如下:



    * Binary files are buffered in fixed-size chunks; the size of the buffer

    *二进制文件以固定大小的块缓冲;缓冲区的大小

    is chosen using a heuristic trying to determine the underlying device's

    使用启发式尝试来确定底层设备的选择。

    "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.

    “块大小”,并回落到“IO。Debug tHuffelySmith'”。

    On many systems, the buffer will typically be 4096 or 8192 bytes long.

    在许多系统中,缓冲器通常为4096或8192字节长。



    * "Interactive" text files (files for which isatty() returns True)

    *“交互式”文本文件(ISATTE()返回true的文件)

    use line buffering. Other text files use the policy described above

    使用行缓冲。其他文本文件使用上面描述的策略

    for binary files.

    用于二进制文件。



    encoding is the name of the encoding used to decode or encode the

    编码是用于解码或编码的编码的名称。

    file. This should only be used in text mode. The default encoding is

    文件。这应该只在文本模式中使用。默认编码是

    platform dependent, but any encoding supported by Python can be

    平台依赖,但任何由Python支持的编码都可以

    passed. See the codecs module for the list of supported encodings.

    通过。参阅支持编码列表的编解码器模块。



    errors is an optional string that specifies how encoding errors are to

    错误是一个可选的字符串,它指定编码错误是如何进行的。

    be handled---this argument should not be used in binary mode. Pass

    处理这个参数不应该用二进制模式。通过

    'strict' to raise a ValueError exception if there is an encoding error

    如果存在编码错误,则“严格”以引发ValueError异常

    (the default of None has the same effect), or pass 'ignore' to ignore

    (默认的“没有”具有相同的效果),或者忽略“忽略”。

    errors. (Note that ignoring encoding errors can lead to data loss.)

    错误。(注意忽略编码错误可能导致数据丢失。)

    See the documentation for codecs.register or run 'help(codecs.Codec)'

    请参阅用于编解码器的文档。注册或运行“帮助(编解码器,编解码器)”。

    for a list of the permitted encoding error strings.

    用于允许的编码错误字符串的列表。



    newline controls how universal newlines works (it only applies to text

    换行符控制通用新行如何工作(只适用于文本)

    mode). It can be None, '', '\n', '\r', and '\r\n'. It works as

    模式)。它可以是“没有”、“n”、“r”和“\r\n”。它起作用

    follows:

    跟随:



    * On input, if newline is None, universal newlines mode is

    *输入时,如果换行符为“否”,则通用换行模式为

    enabled. Lines in the input can end in '\n', '\r', or '\r\n', and

    启用。输入中的行可以以“\n”、“r”或“\r\n”结尾;

    these are translated into '\n' before being returned to the

    这些被翻译成“n”,然后返回到
    the other legal values, input lines are only terminated by the given

    其他法律价值,输入线仅由给定的终止。

    string, and the line ending is returned to the caller untranslated.

    字符串,并将行结束返回给未调用的调用方。



    * On output, if newline is None, any '\n' characters written are

    *输出时,如果换行符为“否”,则写入的“\n”字符均为

    translated to the system default line separator, os.linesep. If

    转换为系统默认行分隔符,OS.LeSeEP。如果

    newline is '' or '\n', no translation takes place. If newline is any

    换行符是''或'n ',没有翻译发生。如果换行符是

    of the other legal values, any '\n' characters written are translated

    在其他法律价值中,任何“N”字都是翻译出来的。

    to the given string.

    给定字符串。



    If closefd is False, the underlying file descriptor will be kept open

    如果LoeFED是false,则底层文件描述符将保持打开。

    when the file is closed. This does not work when a file name is given

    当文件关闭时。当给定文件名时,这不起作用。

    and must be True in that case.

    在那种情况下肯定是真的。



    A custom opener can be used by passing a callable as *opener*. The

    可以通过传递可调用的**开头*使用自定义开头。这个

    underlying file descriptor for the file object is then obtained by

    然后获得文件对象的底层文件描述符。

    calling *opener* with (*file*, *flags*). *opener* must return an open

    用*(*文件*,*标志*)调用*开头*。*开头*必须返回打开

    file descriptor (passing os.open as *opener* results in functionality

    文件描述符(传递OS.OPEN作为*开头*)导致功能性

    similar to passing None).

    类似于没有传递)。



    open() returns a file object whose type depends on the mode, and

    返回类型依赖于模式的文件对象,以及

    through which the standard file operations such as reading and writing

    通过标准文件操作如读写

    are performed. When open() is used to open a file in a text mode ('w',

    被执行。当Open-()用于以文本模式打开文件时,

    'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open

    “R”、“WT”、“RT”等,它返回一个TeXToWrrPAPER。当用于打开时

    a file in a binary mode, the returned class varies: in read binary

    一个二进制模式的文件,返回的类是不同的:在读二进制中

    mode, it returns a BufferedReader; in write binary and append binary

    模式,返回一个BuffReDe读器;写入二进制和附加二进制。

    modes, it returns a BufferedWriter, and in read/write mode, it returns

    它返回一个BuffReDebug写入器,在读/写模式下,它返回。

    a BufferedRandom.

    业余爱好者



    It is also possible to use a string or bytearray as a file for both

    也可以使用字符串或BytErrar作为两个文件。

    reading and writing. For strings StringIO can be used like a file

    阅读和写作。对于字符串,StrugIO可以像文件一样使用。

    opened in a text mode, and for bytes a BytesIO can be used like a file

    在文本模式下打开,对于字节,ByTesto可以像文件一样使用。

    opened in a binary mode.

    以二进制模式打开。



        '''

     baidu_words = '''
    重点词汇
    Open file开文件
    byte string字节串
    current working directory现行工作目录
    file descriptor文件描述符
    set to打起来; 大吃起来; <非正>开始努力干; 把脸转向…
    optional string任选串,任选字符串
    which means这意味着
    text mode文本方式
    truncating截面的( truncate的现在分词 ); 截头的; 缩短了的; 截去顶端或末端
    new file新文件
    untranslated未翻译的
    system default系统设定值
    line separator行分隔符
    file descriptor文件描述符
    does not不
    file name文件名
    must be该是
    in that case如果是那样的话
    can be used使得
    callable可随时支取的,请求即付的,随时可偿还的

        '''


     remark = '''
    open()打开文件用的函数,默认用只读模式打开
     '''

函数open()请参考菜鸟教程:http://www.runoob.com/python/python-func-open.html

猜你喜欢

转载自www.cnblogs.com/wujianghu/p/9789495.html