Makefile function
Python file class objects can read and write directly, and so on, when using the socket to write services, the socket object can be used as a text object directly to read and write performance? The answer is yes, you can use the Makefile function to produce a file class object.
Makefile function:
Returns a socket associated file class object, makefile has two parameters: one for the file class mode, the other for the cached mode, the file class mode contains read-only, write-only and read-write, the cache is mainly used in disk files, but for the interactive network program, it can hinder the operation of the program, It is recommended to close (0).
Instance:
#!/usr/bin/env python#coding:utf-8#filename:makefile demoimport Socketimport sysport = 70host = Sys.argv[1]filename = Sy S.argv[2]s = Socket.socket (socket.af_inet, socket. SOCK_STREAM) fd = S.makefile (' rw ', 0) fd.write (filename + ' \ r \ n ') for line in Fd.readlines (): Sys.stdout.write (line)
This article is from the "26-year-old" blog, please be sure to keep this source http://dbbruce.blog.51cto.com/2061658/1561312
Python--makefile function on the station