譯自 這裡
File Objects :
File objects are implemented using C’s stdio package and can be created with the built-in open() function. File objects are also returned by some other built-in functions and methods, such as os.popen() and os.fdopen() and the makefile() method of socket objects. Temporary files can be created using the tempfile module, and high-level file operations such as copying, moving, and deleting files and directories can be achieved with the shutil module.
When a file operation fails for an I/O-related reason, the exception IOError is raised. This includes situations where the operation is not defined for some reason, like seek() on a tty device or writing a file opened for reading.
下面為 File object 提供的函數 :
- file.close()
- file.flush()
- file.next()
- file.read([size])
- file.readline([size])
- file.readlines([sizehint])
- file.seek(offset[, whence])
- file.tell()
- file.write(str)
- file.writelines(sequence)
以上為檔案物件提供的方法, 其實檔案物件上也有某些屬性值得你參考 :
- file.closed
- file.mode
- file.name
File Objects :
File objects are implemented using C’s stdio package and can be created with the built-in open() function. File objects are also returned by some other built-in functions and methods, such as os.popen() and os.fdopen() and the makefile() method of socket objects. Temporary files can be created using the tempfile module, and high-level file operations such as copying, moving, and deleting files and directories can be achieved with the shutil module.
When a file operation fails for an I/O-related reason, the exception IOError is raised. This includes situations where the operation is not defined for some reason, like seek() on a tty device or writing a file opened for reading.
下面為 File object 提供的函數 :
- file.close()
- file.flush()
- file.next()
- file.read([size])
- file.readline([size])
- file.readlines([sizehint])
- file.seek(offset[, whence])
- file.tell()
- file.write(str)
- file.writelines(sequence)
以上為檔案物件提供的方法, 其實檔案物件上也有某些屬性值得你參考 :
- file.closed
- file.mode
- file.name
This message was edited 25 times. Last update was at 20/03/2012 15:26:41
沒有留言:
張貼留言