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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值