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窗口输出相应信息。
相关文档:
【windows+python3.1.2】
发布python应用程序是个很麻烦的事,因为<1>无法编译原生code<2>每个版本的字节码不同<3>如果直接上源码会损害自己的利益——等等
方法1——手动打包
怎么打包呢?一个python文件夹要二十多MB啊!
yes!我们就要清理无用的东西!
先写一个win.py文件: ......
There should be one—--and preferably only one –--obvious way to do it.
......
设置Emacs的HOME,可以在scratch buffer中输入:(insert (getenv "HOME"))查看
下载python-mode.el
用Emacs打开python-mode.el然后M-x byte-compile-file编译python-mode.el为elc
C-h v查看load-path变量
在HOME/.emacs.d/init.el中添加(setq load-path (cons "D:\\emacs-23.1-bin-i386" load-path))
将py文件与pytho ......
总结下,Python 下载网页的几种方法
1
fd = urllib2.urlopen(url_link)
data = fd.read()
这是最简洁的一种,当然也是Get的方法
2
通过GET的方法
def GetHtmlSource(url):
try:
htmSource = ''
&nb ......
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 ......