![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
justdoit1024
永不止步!
展开
-
处理中文
只需在文件第一行加上[code="java"]# -*- coding: UTF-8 -*-[/code]2010-04-13 15:47:43 · 72 阅读 · 0 评论 -
Python获取本机公网IP(windows、Linux下通用)
[code="java"]class Getmyip: def getip(self): try: myip = self.visit("http://www.ip138.com/ip2city.asp") except: try: myip = self.visit...2010-04-23 15:24:59 · 621 阅读 · 0 评论 -
文件夹差异文件对比工具
[code="java"]# -*- coding:UTF-8 -*-'''Created on 2010-4-30@author: shiyong'''import osclass Compare(object): ''' 文件夹比较工具 功能:目前只未比较文件的名称和大小,未比较md5 ''...2010-05-05 15:44:02 · 174 阅读 · 0 评论 -
Python HTTP文件上传
[code="java"]# -*- coding:UTF-8 -*-'''Created on 2010-4-26@author: shiyong'''import urllibimport sysimport urllib2import mimetools, mimetypesimport os, statfrom IdongNet import...原创 2010-05-06 11:08:41 · 839 阅读 · 0 评论 -
Python截屏程序
说明:必须安装PIL库[code="java"]# -*- coding:UTF-8 -*-'''Created on 2010-5-6@author: shiyong'''import osfrom PIL import ImageGrabimport timeclass Capturer(object): '''截屏程序''...原创 2010-05-06 13:31:28 · 130 阅读 · 0 评论 -
py2exe简单使用
1、首先下载已安装的对应Python版本的py2exe2、将写好的程序拷入类似文件夹C:\Python26\Lib\site-packages\py2exe\samples3、假设写好的程序全部放在capturer文件夹中4、编写setup.py如下:[code="java"]from distutils.core import setupimport py2exe...原创 2010-05-06 15:46:39 · 109 阅读 · 0 评论 -
wxPython GUI菜单示例
1、main.py[code="java"]#!/usr/bin/env python#Boa:App:BoaAppimport wximport mainFramemodules ={'mainFrame': [1, 'Main frame of Application', 'mainFrame.py']}class BoaApp(wx.App): ...原创 2010-05-07 22:31:21 · 260 阅读 · 0 评论 -
Python实现ping命令
[code="java"]#!/usr/bin/env python# -*- coding: iso-8859-1 -*-"""ping.py ping.py uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or ga...原创 2010-05-08 12:49:55 · 1261 阅读 · 0 评论 -
Python多线程实例
特别注意:加锁的位置一定要只包住临界资源,如:[code="java"]self.stateLock.acquire()tstate = self.stateself.stateLock.release()[/code][code="java"]class NetworkMgr(object): ''' 网络设置管理 ''' ...原创 2010-05-08 17:01:18 · 92 阅读 · 0 评论 -
Python sqllit实例
1、操作数据库[code="java"]# -*- coding: UTF-8 -*-'''Created on 2010-6-7@author: qxf'''import sysimport osfrom sqlite3 import connect, Connectionimport UpdateLogclass VisitSqlite...原创 2010-07-15 10:21:00 · 189 阅读 · 0 评论 -
python比较值类型是否为字符串
[code="java"]value:要判断的值isinstance(value, basestring)返回Boolean类型[/code]原创 2010-08-04 14:56:31 · 98 阅读 · 0 评论 -
python发送邮件
[code="java"]# -*- coding:UTF-8 -*-'''Created on 2010-5-27@author: 忧里修斯'''import smtplibimport emailimport osimport traceback from email.message import Messagefrom email.mime.m...原创 2010-05-27 11:15:53 · 90 阅读 · 0 评论 -
Python日期计算
1、将字符串转换成date[code="java"]nowDate = time.strptime('2010-05-27', "%Y-%m-%d")[/code]2、获取年、月、日[code="java"]year = nowDate[0]month = nowDate[1]day = nowDate[2][/code]3、日期想减,计算天数[code="java...原创 2010-05-28 10:38:07 · 175 阅读 · 0 评论 -
python编码问题
[code="java"]出现错误:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 2: ordinal not in range(128)分清encode和decode。str --> decode(c) --> unicode, unicode --> encode(c) --> str,其中...原创 2010-08-23 13:26:13 · 130 阅读 · 0 评论 -
ubuntu下使用apache发布Django应用
一、安装Django1、下载地址http://www.djangoproject.com/download/2、安装[code="java"]tar xzvf Django-1.2.3.tar.gz #解压cd Django-1.2.3 #进入解压目录sudo python setup.py install #安装[/code]二、安装my...原创 2010-12-20 09:21:57 · 120 阅读 · 0 评论 -
python打印详细的异常信息
[code="java"]import tracebackprint traceback.format_exc()[/code]原创 2010-09-20 15:44:09 · 249 阅读 · 0 评论 -
python获取系统、平台相关的信息
python获取系统、平台相关的信息可使用以下两个模块:import platformimport os如:获取处理器类型print platform.machine()原创 2010-10-26 16:23:29 · 76 阅读 · 0 评论 -
Python随机生成字符串
[code="java"]class RandomUtil(): '''随机数生成工具类''' @staticmethod def randomString(length): '''生成长度为length的随机字符串''' rstr = '' while(len(rstr) < length): ...2010-04-22 15:25:46 · 127 阅读 · 0 评论 -
Python执行外部程序
[code="java"]# -*- coding:UTF-8 -*- import osimport subprocessclass ExeMgr(object): '''Python管理应用程序 ''' def __init__(self,appPath): ''' appPath:要启动的应用程序的...2010-04-21 15:52:38 · 116 阅读 · 0 评论 -
Python使用xml.etree.ElementTree解析xml文件
示例一、data.xml[code="java"] 保存用户的信息 jiaoshe_15 小丸子 12345678 44 女 上网,打游戏 我是一个来自广东深圳的女十,我期待和喜爱运动的你成为朋友 jiaoshe_12 功夫老伯 aa33678 78 男 功夫 我是一个老伯,我...2010-04-14 14:06:26 · 186 阅读 · 0 评论 -
python下载文件
[code="java"]# -*- coding: UTF-8 -*-import urllibimgurl = r'http://xidong.net/xdpic_n/6040308/1245564.gif'save_path = r'F:\t.gif'urllib.urlretrieve(imgurl, save_path)print '下载成功'[/code...2010-04-14 15:20:04 · 57 阅读 · 0 评论 -
python自动登录网站
[code="java"]# -*- coding:UTF-8 -*-'''Created on 2010-5-8@author: 忧里修斯'''import urllib2def login(name,ps): opener=urllib2.build_opener(urllib2.HTTPCookieProcessor()) open...2010-04-14 16:56:29 · 251 阅读 · 0 评论 -
Python异常总结
1、EOFError如果文件的内容为空,则使用load()时会抛EOFError异常[code="java"]targetFile = r'F:\personinfo.txt'readfile = file(self.targetFile,'r')self.personList = cp.load(readfile)[/code]...2010-04-15 12:41:23 · 95 阅读 · 0 评论 -
Python GUI简单示例
Python GUI简单示例(Tkinter)2010-04-15 15:02:37 · 91 阅读 · 0 评论 -
python简单的http服务器
1、Server.py[code="java"]# -*- coding:UTF-8 -*-import osimport BaseHTTPServerimport timeimport threadingimport urlparseclass ServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...2010-04-15 16:28:10 · 115 阅读 · 0 评论 -
简易web服务器版本二
[code="java"]# -*- coding:UTF-8 -*-import osimport BaseHTTPServerimport timeimport threadingimport urlparseclass ServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): ''' ...2010-04-15 21:54:36 · 75 阅读 · 0 评论 -
解析除请求的参数
请求的URL为[code="java"]http://localhost/?cmd=searchUser[/code][code="java"]str = urlparse.urlparse(self.path)#请求的参数args = dict(urlparse.parse_qsl(str.query))#得到的cmd的值为searchUsercmd = args['cm...2010-04-16 09:15:17 · 81 阅读 · 0 评论 -
Linux下Python执行C函数
1、util.c代码如下:[code="java"]#includevoid display(char* msg){ printf("%s\n",msg);}int add(int a,int b){ return a+b;}[/code]2、编译c代码,最后生成Python可执行的.so文件(1)gcc -c util.c,将生...2010-04-17 16:42:18 · 177 阅读 · 0 评论 -
windows下Python调用dll
一、使用VC++生成一个.dll文件1、打开VC++新建一个“Win32 Dynamic_Link Library”空工程2、编写头文件Lib.h[code="java"]#ifndef LIB_H#define LIB_Hextern "C" int __declspec(dllexport)add(int x, int y);#endif[/code]3、编写主文件...2010-04-19 09:33:05 · 152 阅读 · 0 评论 -
Python静态方法的使用
1、将Python中的一个类的方法设为静态的(即通过类名就可以调用),只需在方法名前加上“@staticmethod”[code="java"]class PersonManager(object): @staticmethod def saveOrUpdatePerson(person): '''保存、更新一个联系人''' name =...2010-04-19 16:30:51 · 254 阅读 · 0 评论 -
Python动态生成xml文件
1、类Person[code="java"]# -*- coding:UTF-8 -*-class Person(object): ''' 联系人:姓名,性别(0:男,1:女),手机 ''' name = None sex = None mobile = None def __init__(self,...2010-04-19 17:30:36 · 427 阅读 · 0 评论 -
Python判断问价是否为空
[code="java"]def isFileEmpty(filepath): '''判断文件的内容是否为空''' fileSize = os.stat(filepath).st_size if fileSize == 0: return True else: return ...2010-04-19 17:32:51 · 113 阅读 · 0 评论 -
Python使用xml.etree.ElementTree操作xml文件
一、基本知识1、插入节点Element.insert(index, element) 、ET.SubElement(parent, tag[, attrib[, **extra]]) 、Element.append(subelement)2、删除节点Element.remove(subelement) 删除一个节点、Element.clear()删除该节点下所有子节点3、在节点...2010-04-20 13:29:58 · 1045 阅读 · 0 评论 -
Python根据对象实例获取对象的属性值(getattr方法)
如Person对象有属性:name,age[code="java"]p = Person('忧里修斯','男')[/code]则在其他类中,可以使用[code="java"]sex = getattr(p, 'name')获取其值[/code]2010-04-20 15:01:21 · 459 阅读 · 0 评论 -
Python对象转换为xml
[code="java"]# -*- coding:UTF-8 -*-'''Created on 2010-4-20@author: 忧里修斯'''import xml.etree.ElementTree as ETimport xml.dom.minidom as minidomfrom addrbook.domain import Personclass...2010-04-20 17:41:41 · 680 阅读 · 0 评论 -
【转】Python如何使用urllib2获取网络资源
urllib2是Python的一个获取URLs(Uniform Resource Locators)的组件。他以urlopen函数的形式提供了一个非常简单的接口,这是具有利用不同协议获取URLs的能力,他同样提供了一个比较复杂的接口来处理一般情况,例如:基础验证,cookies,代理和其他。它们通过handlers和openers的对象提供。urllib2支持获取不同格式的URLs(在URL的”:...原创 2010-10-29 20:04:41 · 109 阅读 · 0 评论