Python Socket编程
1,编写Server.py
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('localhost',8081))
while True:
data,addr=s.recvfrom(1024)
print 'receive:',data,'from',addr
2,编写Client.py
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
while True:
msg=raw_input()
s.sendto(msg,('localhost',8081))
3,运行程序
不同cmd窗口,分别运行两个py。Client窗口输入信息,Server窗口输出相应信息。
相关文档:
代码+结果,不做解释
当然,对于python没有virtual function一说,估计当作对比一个例子看看吧。
#include <iostream>
using namespace std;
class base
{
public:
virtual void foo() { cout << "base" << endl; }
base() { foo() ;}
};
class derive: public base
{
pub ......
import urllib2
import time
import socket
from datetime import datetime
from thread_pool import *
def main():
url_list = {"sina":"http://www.sina.com.cn",
"sohu":"http://www.sohu.com",
"yahoo":"http://www.yahoo.com",
"xiaonei":"http://www.x ......
1、str类型可以理解为一个二进制block,或multibyte
2、multibyte_str.decode("<multibyte_encode_method>") -> unicode
3、unicode_str.encode("<multibyte_encode_method>") -> multibyte_str(binary block)
4、unicode_str 的操作参数也应为unicode,如:unicode_str.find("样本".deco ......
import urllib
from HTMLParser import HTMLParser
class TitleParser(HTMLParser):
def __init__(self):
self.title = ''
self.divcontent = ''
self.readingtitle = 0
self.readingdiv = 0
HTMLParser.__init__(self)
def handle_starttag(self, tag, attrs):
......
1,下载org.python.pydev.feature-1.5.0.1251989166.zip http://sourceforge.net/projects/pydev/files/
2,安装插件到eclipse
3,重启eclipse
注意:使用1.5.6版本pydev插件,创建python工程会报错,使用1.5.0版本无此问题。 ......