我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用os.O_TEXT。
def flags(self): ''' Adapted from http://hg.python.org/cpython/file/84cf25da86e8/Lib/_pyio.py#l154 See also open(2) which explains the modes os.O_BINARY and os.O_TEXT are only available on Windows. ''' return ( ((self.reading and not self.updating) and os.O_RDONLY or 0) | ((self.writing and not self.updating) and os.O_WRONLY or 0) | ((self.creating_exclusively and not self.updating) and os.O_EXCL or 0) | (self.updating and os.O_RDWR or 0) | (self.appending and os.O_APPEND or 0) | ((self.writing or self.creating_exclusively) and os.O_CREAT or 0) | (self.writing and os.O_TRUNC or 0) | ((self.binary and hasattr(os, 'O_BINARY')) and os.O_BINARY or 0) | ((self.text and hasattr(os, 'O_TEXT')) and os.O_TEXT or 0) )
def create_file_from_handle(handle, mode="r"): """Return a Python :class:`file` around a ``Windows`` HANDLE""" fd = msvcrt.open_osfhandle(handle, os.O_TEXT) return os.fdopen(fd, mode, 0)
def File2FileObject(pipe, mode): """Make a C stdio file object out of a win32 file handle""" if mode.find('r') >= 0: wmode = os.O_RDONLY elif mode.find('w') >= 0: wmode = os.O_WRONLY if mode.find('b') >= 0: wmode = wmode | os.O_BINARY if mode.find('t') >= 0: wmode = wmode | os.O_TEXT return os.fdopen(msvcrt.open_osfhandle(pipe.Detach(),wmode),mode)