Python Socket 编程
client:
import socket, sys
if __name__ == '__main__':
#处理参数
argv = sys.argv
if (len(argv)!=3) or (len(argv)==2 and argv[1]=='/?'):
print '>>>Useage:', argv[0], '<address> <port>'
sys.exit(0)
HOST = argv[1] #Server IP地址
PORT = int(argv[2]) #Server 端口
print '>>>HOST:', HOST
print '>>>PORT:', PORT
#打开socket
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print '>>>Fail to open socket!'
sys.exit(1)
print '>>>Socket opened...'
#连接
try:
sock.connect((HOST, PORT))
except socket.error:
print '>>>Fail to connect!'
sock.close()
print '>>>Socket closed...'
sys.exit(1)
print '>>>Socket connected...'
flag = 1 #循环标志
iReturnValue = 0 #系统返回值
#向Server发送信息并回显
while(flag):
msg = raw_input('>>>Input message: ')
if msg == '':
&
相关文档:
ZoundryDocument
Python skin is known for its color variations and for its elasticity; it is
the warmest leather of the season and ideal for the manufacture of many luxury
goods. Sometimes natural patterns can be hidden when they're done in black, but
the finish here has a bit of a shine to it ......
1. 事件驱动
一个事件及其回调的例子是鼠标移动。我们假设鼠标指针停在您GUI 程序的某处。如果鼠标被移到了程序的别处,一定是有什么东西引起了屏幕上指针的移动,从而表现这种位置的转移。系统必须处理这些鼠标移动事件才能展现(并实现)鼠标在窗口上的移动。一旦您释放了鼠标,就不再会有事件需要处 ......
偶然需要用到这样一个函数,在Delphi中,有现成的函数可以调用!在python中,我找了半天都还没找到,最后自己写了一个函数如下:
def dayOfMonth(date):
if date.month == 12:
return 31
else:
return (date.replace(month=date.month+1, day=1) - datetime.timedelta(days=1)).day
......
刚刚写完Python嵌入部分的简单例子(差不多够现在用的啦~),接着看点实际的东西,如果没有这些应用的话,前面的嵌入也没有什么意义。嵌入的其他部分以后遇到再写,不必一下子把那些函数都弄懂,是吧~
OK,来看Python库中我认为最好玩的一部分,也就是Python对网页的操作。
这篇简单说下如何通过网址下载网页,前提当然是 ......
Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.
There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various man ......