python根据主机名字获得所有ip地址# -*- coding: utf-8 -*-import sys, socketresult = socket.getaddrinfo('www.google.com', None, 0, socket.SOCK_STREAM)counter = 0for item in resul……继续阅读 » 4年前 (2021-01-15) 1338浏览 126个赞
一个简单python ftp客户端代码#!/usr/bin/python# -*- coding: utf-8 -*-import ftplibimport osimport socketHOST = 'ftp.mozilla.org'DIRN = 'pub/mozilla.org/webtools'……继续阅读 » 4年前 (2021-01-15) 2682浏览 843个赞
一段简单的python邮件客户端发送代码#/usr/bin/python# -*- coding: utf-8 -*-import reimport smtplibfrom poplib import POP3from email.mime.text import MIMETextdef sevname(username): pa ……继续阅读 » 4年前 (2021-01-15) 2165浏览 2650个赞
python实现自动登录人人网并采集信息的代码#!/usr/bin/python# -*- coding: utf-8 -*-import sysimport reimport urllib2import urllibimport cookielibclass Renren(object): def __init__(se……继续阅读 » 4年前 (2021-01-15) 2412浏览 2186个赞
python代码用于查找指定具有相同内容的文件,可以同时指定多个目录调用方式:python doublesdetector.py c:\;d:\;e:\ > doubles.txt# Hello, this script is written in Python - http://www.75271.com# doublesdetector.py 1……继续阅读 » 4年前 (2021-01-15) 2762浏览 1783个赞
python Gevent multiprocessing serverimport sysfrom gevent import serverfrom gevent.baseserver import _tcp_listenerfrom gevent.monkey import patch_all; patch_all()from multi……继续阅读 » 4年前 (2021-01-15) 2926浏览 331个赞
一个使用进程内通讯的python聊天室代码,非常简单的服务端和客户端代码#!/usr/bin/env python# Added by <ctang@redhat.com>import sysimport osfrom multiprocessing import connectionADDR = ('', 9……继续阅读 » 4年前 (2021-01-15) 2408浏览 839个赞
这段代码可以对指定的目录进行扫描,包含子目录,对指定扩展名的文件进行SHA-1加密后存储在cvs文件,以防止文件被篡改调用方法:python snapper.py > todayCheck.csv# Hello, this is a script written in Python. See http://www.pyhon.org## Snapp……继续阅读 » 4年前 (2021-01-15) 2312浏览 218个赞
我用这段代码来压缩数据库备份文件,没有使用python内置的zip模块,而是使用了zip.exe文件# Hello, this script is written in Python - http://www.75271.com## autozip.py 1.0p## This script will scan a directory (and……继续阅读 » 4年前 (2021-01-15) 2025浏览 234个赞
这段python可以用来读取新闻组内的新闻,并保存为纯文本文件# Hello, this script is written in Python - http://www.75271.com## newsarchiver 1.1p - Newsgroup archiver## Purpose:# This script will dow……继续阅读 » 4年前 (2021-01-15) 1926浏览 1716个赞
python打印ASCII编码字符代码i = 0while i < 256: print chr(i), if i != 0 and i % 8 == 0 : print i = i + 1……继续阅读 » 4年前 (2021-01-15) 2590浏览 1477个赞
python实现的矩阵乘法def matrixMul(A, B): res = [[0] * len(B[0]) for i in range(len(A))] for i in range(len(A)): for j in range(len(B[0])): for k in range(le……继续阅读 » 4年前 (2021-01-15) 2064浏览 948个赞
There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit …'''primelist_timing1.pytiming some very fas……继续阅读 » 4年前 (2021-01-15) 2174浏览 1139个赞
This snippet allows one to implement an equivalent of a __getattr__() function in a python module. The module can then define its own way to lazily import abitrary symbols. For exa……继续阅读 » 4年前 (2021-01-15) 2429浏览 594个赞
python从任意文件读取邮件地址输出,包括html、txt甚至exe文件调用方法:python email_extractor.py < PythonFAQ.html# Hello, this script is written in Python - http://www.75271.com# Script written by Sebastie……继续阅读 » 4年前 (2021-01-15) 2128浏览 1324个赞
python 操作 ssh#coding:utf-8""" ssh操作例子 实现了服务器日志下载 2012-08-24 yywolf"""import paramikoimport timehostname="????"port=22u……继续阅读 » 4年前 (2021-01-15) 3075浏览 612个赞
python统计cpu的利用率#-*-coding=utf-8-*-import win32pdhimport time# Counter pathsPROCESSOR_PERCENT = r'\Processor(_Total)\% Processor Time'MEMORY_PERCENT = r'\Memo……继续阅读 » 4年前 (2021-01-15) 2058浏览 2231个赞
python 使用socket远程发送命令并获得执行结果 #socket_server.pyimport socketimport osimport sysdef work(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(……继续阅读 » 4年前 (2021-01-15) 2094浏览 296个赞
python实现线程池原理:建立一个任务队列,然多个线程都从这个任务队列中取出任务然后执行,当然任务队列要加锁,详细请看代码出处:http://blog.csdn.net/liujian0616/article/details/7951081import threadingimport timeimport signalimport oscla……继续阅读 » 4年前 (2021-01-15) 2296浏览 790个赞
用python实现windows服务-在服务中新建进程出处:http://blog.csdn.net/liujian0616/article/details/7950758 需要安装的软件:python和pywin32,我这里装的分别是python-2.6.amd64、pywin32-……继续阅读 » 4年前 (2021-01-15) 1972浏览 860个赞
python xmlrpc实现二进制文件传输的代码 服务器端from SimpleXMLRPCServer import SimpleXMLRPCServerimport xmlrpclib def python_logo(): handle = open(&quo……继续阅读 » 4年前 (2021-01-15) 1487浏览 1855个赞
python urllib.urlencode用法演示>>> import urllib >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) >>> f =……继续阅读 » 4年前 (2021-01-15) 2418浏览 1277个赞
python写的FTP简单上传下载文件出自 “王伟” 博客,请务必保留此出处http://wangwei007.blog.51cto.com/68019/983638#!/usr/bin/env python # -*- coding: utf-8 -*- from ftplib import FTP def ftp_up(filenam……继续阅读 » 4年前 (2021-01-15) 2533浏览 673个赞
通过python自动连接ssh服务器#!/usr/bin/python#-*- coding:utf-8 -*-import sys, time, ostry: import pexpectexcept ImportError: print """ You must install ……继续阅读 » 4年前 (2021-01-15) 2765浏览 301个赞
python判断文件和文件夹是否存在import osos.path.isfile('test.txt') #如果不存在就返回Falseos.path.exists(directory) #如果目录不存在就返回False……继续阅读 » 4年前 (2021-01-15) 2216浏览 1992个赞
python通过urllib2提交http post请求#!/usr/bin/python #coding=utf-8 import urllib import urllib2 def post(url, data): req = urllib2.Request(url) data = urllib.……继续阅读 » 4年前 (2021-01-15) 2910浏览 1790个赞
python根据域名获得ip地址def getIp(domain): import socket myaddr = socket.getaddrinfo(domain,'http')[0][4][0] print(myaddr) 其中d……继续阅读 » 4年前 (2021-01-15) 1304浏览 119个赞
python 2.6 引入了itertools模块,使得排列组合的实现非常简单import itertools #排列:e.g., 4个数内选2个排列>>> print list(itertools.permutations([1,2,3,4],2)) [(1, 2), (1, 3), (1, 4), (2, 1), (2,……继续阅读 » 4年前 (2021-01-15) 2482浏览 1107个赞
Python从ftp服务器下载文件的代码#coding=utf-8''' ftp自动下载、自动上传脚本,可以递归目录操作'''from ftplib import FTPimport os,sys,string,datetime,timeimport socketclass MY……继续阅读 » 4年前 (2021-01-15) 1670浏览 987个赞
Python的shelve模块提供了一种简单的数据存储方案,以dict(字典)的形式来操作数据。#!/usr/bin/pythonimport sys, shelvedef store_person(db): """ Query user for data and store it in the she……继续阅读 » 4年前 (2021-01-15) 1868浏览 1359个赞
python通过ip查询网站获得本地ip的代码import reimport urllib.requestclass GetIP(): def get_external_ip(self, nurl='http://city.ip138.com/city0.asp'): try: o……继续阅读 » 4年前 (2021-01-15) 2506浏览 1586个赞
python 通过logging写入日志到文件和控制台import logging # 创建一个logger logger = logging.getLogger('mylogger') logger.setLevel(logging.DEBUG) # 创建一个handler,用于写入日志文件 fh ……继续阅读 » 4年前 (2021-01-15) 1741浏览 1004个赞
python通过socket进行通信的简单范例,带客户端和服务器端 服务器端from socket import *import threadPORT=5648BUFSIZE=1024def th(): while True: data=raw_input("……继续阅读 » 4年前 (2021-01-15) 2100浏览 2484个赞
python编写的一个超级简单的密码生成器import randomimport stringpass_gen = lambda length, ascii = string.ascii_letters + string.digits + string.punctuation: "".join([list(set(ascii)……继续阅读 » 4年前 (2021-01-15) 1997浏览 2448个赞
python将字符串转换成数组的代码#------------------------------------------------------------------------------# Name: string_to_array.py# Author: Kevin Harris# Last Mod……继续阅读 » 4年前 (2021-01-15) 1947浏览 2991个赞
python复制文件的代码演示和详解 本文涉及到的有Python复制文件在实际应用操作方案的实际应用以及Python复制文件 的相关的代码的详解,如果你对其有兴趣的话,你就可以点击以下的文章浏览我们的文章,望你会有所收获。Python复制文件import shu……继续阅读 » 4年前 (2021-01-15) 1279浏览 1454个赞
python内置了timeit模块,通过它可以很简单的计算出代码执行时间,可以通过number参数控制代码的执行次数,非常好用。更详细的实用方法可以参考:http://docs.python.org/2/library/timeit.html>>> import timeit>>> timeit.timeit(……继续阅读 » 4年前 (2021-01-15) 2212浏览 1681个赞
python利用PIL给图片打水印水印import Image, ImageEnhancedef reduce_opacity(im, opacity): """Returns an image with reduced opacity.""" assert opacity ……继续阅读 » 4年前 (2021-01-15) 2274浏览 198个赞
如:int,str,char,float,ord,hex,oct等类型的相互转换代码int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) 将x转换到一个浮点数 complex(real [,imag ]) 创……继续阅读 » 4年前 (2021-01-15) 1834浏览 2124个赞
python通过点操作符和reduce遍历对象的属性class Klass(object): def __getattr__(self, name): """ Locate the function with the dotted attribute. ……继续阅读 » 4年前 (2021-01-15) 1878浏览 1144个赞
python搜索指定目录的代码演示#------------------------------------------------------------------------------# Name: search_directory.py# Author: Kevin Harris# Last Mod……继续阅读 » 4年前 (2021-01-15) 1304浏览 1222个赞
python随机生成一个简单的密码代码import randomimport sysdef main(argv): if (len(sys.argv) != 2): sys.exit('Usage: simple_pass.py <password_length>') password = ……继续阅读 » 4年前 (2021-01-15) 1716浏览 977个赞
Image对象有open方法却没有close方法,如果打开图片,判断图片高度和宽度,判断完成后希望删除或者给图片改名,是无法操作的,这段代码可以解决这个问题,注意open函数打开图片文件要使用二进制方式,及参数使用’rb’,有的文章给出的只有个’r’参数,Image是无法open的fileName = &……继续阅读 » 4年前 (2021-01-15) 3125浏览 864个赞
本篇将介绍python中sys, getopt模块处理命令行参数 如果想对python脚本传参数,python中对应的argc, argv(c语言的命令行参数)是什么呢?需要模块:sys参数个数:len(sys.argv)脚本名: &nbs……继续阅读 » 4年前 (2021-01-15) 2286浏览 421个赞
python获取从命令行输入的数字代码演示#------------------------------------------------------------------------------# Name: numerical_input.py# Author: Kevin Harris# Last ……继续阅读 » 4年前 (2021-01-15) 2336浏览 504个赞