python网络编程1

python的sendall和c的send对比



python的文件对象:只要实现了文件对象必须的几个方法,就可以当作“文件”一样操作,duck type,有文件对象,也有file-like ojbect,后者并不一定有文件对象的全部方法和属性。
File Objects
====================
File objects are implemented using C's stdio package.
1, can be created with the built-in open() function
2, returned by some methods,such as os.popen(),os.fdopen(),makefile() method of socket objects
Temporary fils can be created using the tempfile module
>>> from tempfile import *
>>> f = NamedTemporaryFile(delete=False)
>>> f.name
'/tmp/tmpV3sfCh'
>>> f.write('hello\n')
>>> f.read()
''
>>> f.close()
>>> f.name
'/tmp/tmpV3sfCh'
>>> import os
>>> os.unlink(f.name)
>>> os.path.exists(f.name)
False


copying,moving... can be achieved with shutil module

Exception:IOError
Method:
close() operation which requires that the file be open will rais a ValueError after the file has been closed.
flush() C:fflush()
fileno() Return the integer "file descriptor" that is used by the underlying implementations to req I/O
isatty() tty(like) device?
next() Ex:StopIteration when EOF is hit. has a read-ahead buf
read([size])  C:fread
readline([size]) C:fgets .unlike fgets,the returned sring contains null character('\0') if they occurred in the input
readlines([sizehint])
xreadlines()   returns the same thing as iter(f)
should for line in file instead.
seek(offset[,whence]) C:fseek
f.seek(2, os.SEEK_CUR)
f.seek(-3, os.SEEK_END)
tell()   C:ftell
truncate
write(str)
writelines(sequence) eg:list of strings
closed()
encoding if encoding is None,in which case the file uses the system default encoding for converting Unicode strings.
file.errors  unicode error handler used along with the encoding
mode
name
newlines

你可能感兴趣的:(编程,c,python,OS,F#)