ChinaUnix.net
相关文章推荐:

python实现聊天室

转自 http://www.lixiaodou.cn/?cat=8 # -*- coding: utf-8 -*- def charu(list): length = len(list) for i in range(1,length): temp = list j = i - 1 while list[j] > temp: list[j+1] = list[j] list[j] = temp j = j - 1 if j 0: break return list def xuanze(list): length = len(list) for i in range...

by BENNYSNAKE - Python文档中心 - 2009-05-25 18:05:36 阅读(1258) 回复(0)

相关讨论

爬虫工作的基本原理就是,给定一个初始的url,下载这个url的网页,然后找出网页上所有满足下载要求的链接,然后把这些链接对应的url下载下来,然 后再找下载下来的这些网页的url,我们可以用广度优先搜索实现这个算法. #!/usr/bin/python import urllib2 import re def downURL(url,filename): print url print filename try: fp = urllib2.urlopen(url) except: print 'download exception' ...

by alexnetwork - Python文档中心 - 2009-03-18 21:49:45 阅读(1406) 回复(0)

python实现> 最近在学习python,又不知道写个什么来练手,就想到用python实现>里面的例程, <一> 第二章,例2-3的清除函数: #! /usr/bin/env python # -*- coding:utf-8 -*- #TO: #BY: #File: cleanup.py #Date: 2008-00-12/26/08 # import os import sys LOG_DIR="/var/log" ROOT_UID=0 LINES=50 E_XCD=65 E_NOTROOT=67 if os.getuid() != ROOT_UID: print "Must be root to run this script." sys.exit(E...

by yk325 - Python文档中心 - 2008-12-26 15:42:04 阅读(1333) 回复(0)

Example 4: Koch curveA variant of the Koch curve which uses only right-angles. variables : F constants : + − start : F rules : (F → F+F−F−F+F) Here, F means "draw forward", + means "turn left 90°", and - means "turn right 90°"(see turtle graphics). n = 0: F n = 1: F+F-F-F+F n = 2: F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F n = 3: F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+...

by blackjimmy - Python - 2009-05-10 12:32:08 阅读(1537) 回复(0)

#!/usr/bin/python import smtplib, email import os, sys import hashlib def send_mail(send_from, send_to, subject, text, attachment_bytes, auth=(), send_server='localhost'): msg = email.MIMEMultipart.MIMEMultipart() msg['From'] = send_from msg['To'] = email.Utils.COMMASPACE.join(send_to) msg['Date'] = email.Utils.formatdate(localtime=True) msg['Subject'] = subject msg.atta...

by alexnetwork - Python文档中心 - 2009-03-18 20:54:33 阅读(1386) 回复(0)

#!/usr/bin/python import sendpkt import dpkt import os import re import socket import struct import string import sys import signal iface = "eth0" mac = "00:09:5B:98:0D:85" inet = "10.29.1.61" debug = False # this should be somewhere is dpkt ? ETH_ADDR_BROADCAST = '\xff\xff\xff\xff\xff\xff' ETH_ADDR_UNSPEC = '\x00\x00\x00\x00\x00\x00' def eth_ntoa(buffer): # Convert binary data into a stri...

by alexnetwork - Python文档中心 - 2009-03-18 13:20:56 阅读(2271) 回复(0)

#!/usr/bin/env python """ping.py ping.py uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. Copyright (C) 2004 - Lars Strand ; This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at you...

by alexnetwork - Python文档中心 - 2009-03-18 13:13:24 阅读(1796) 回复(0)

UDP协议相比TCP要简单许多,虽然数据无法保证完整性. 先看一下client端的演示代码: import socket s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) port = 8000 host = '192.168.1.102' while True: msg = raw_input() if not msg: break s.sendto(msg,(host,port)) s.close() 注意,在创建socket的时候,第二个参数要为SOCK_DGRAM,然后,我们只需要调用sendto即可以了,真是太方便了. 再看看serve...

by riverbird2005 - Python文档中心 - 2009-03-15 18:26:05 阅读(1349) 回复(0)

1.有时间就来研究研究python中的lib包下面的所有模块代码,写得相当有水平的! 实现一个简单的HTTP服务器 #Copyright Jon Berg , turtlemeat.com import string,cgi,time from os import curdir, sep from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer #import pri class MyHandler(BaseHTTPRequestHandler): def do_GET(self): try: if self.path.endswith(".html"): f = ...

by hkebao - Python文档中心 - 2009-02-03 12:57:38 阅读(2617) 回复(0)

webdir = '.' # where your HTML files and cgi-bin script directory live port = 80 # http://servername/ if 80, else use http://servername:xxxx/ import os, sys from BaseHTTPServer import HTTPServer from CGIHTTPServer import CGIHTTPRequestHandler #处理CGI程序的 if len(sys.argv) > 1: webdir = sys.argv[1] # command-line args if len(sys.argv) > 2: port = int(sys.argv[2]) ...

by hkebao - Python文档中心 - 2009-02-02 17:03:39 阅读(1663) 回复(0)

There is currently no switch statement in python. Often this is not a problem and can be handled through a series of if-elif-else statements. However, there are many other ways to handle the deficiency. The following example shows how to create a simple switch statement in python: def a(s): print s def switch(ch): try: {'1': lambda : a("one"), '2': lambda : a(...

by panix - Python文档中心 - 2007-09-20 23:16:48 阅读(1027) 回复(0)