python正则表达式提取网页URLimport reimport urlliburl="http://www.itokit.com"s=urllib.urlopen(url).read()ss=s.replace(" ","")urls=re.findall(r"<……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1687浏览 241个赞
Windows下Python获取磁盘空闲空间并写入日志from ctypes import *import timeimport win32filerun = Truelogfile = open('.\\log.out','w+');#open log fileinput = raw_input(&q……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2463浏览 265个赞
用urllib按照百度音乐分类下载mp3。#!/usr/bin/env python#-*- coding: utf-8 -*-import urllibimport rebaseurl = "http://music.baidu.com"url = "http://music.baidu.com/search/……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2018浏览 2002个赞
python处理大数字代码# check the numeric range of Python with huge factorials# factorial(69) still checks out accurately! Has 98 digits in it!# 171122452428141311372468338881272839092……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2108浏览 1774个赞
上线需要,将py的源码中注释删掉,然后编译成字节码。写此脚本主要是为了删除注释。当然如果上线不想放py源码,则在最后增加删除源码即可。#!/bin/env python# -*- coding:utf-8 -*-# -------------------------------# Filename: # Revision:# Date:……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3105浏览 2641个赞
python提取页面内的url列表from bs4 import BeautifulSoupimport time,re,urllib2t=time.time()websiteurls={}def scanpage(url): websiteurl=url t=time.time() n=0 html=……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2726浏览 2757个赞
python 类继承演示范例# a simple example of a class inheritance# tested with Python24 vegaseat 10aug2005help('object') # testclass Class1(object): ""&……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3363浏览 2860个赞
python统计文本字符串里面单词出现的频率# word frequency in a text# tested with Python24 vegaseat 25aug2005# Chinese wisdom ...str1 = """Man who run in front of car, get t……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3113浏览 1917个赞
python正则搜索范例,通过search正则搜索字符串# encoding: UTF-8 import re # 将正则表达式编译成Pattern对象 pattern = re.compile(r'world') # 使用search()查找匹配的子串,不存在能匹配的子串时将返回None # 这个例子中使用mat……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2859浏览 1558个赞
python 定时执行指定的函数# time a function using time.time() and the a @ function decorator# tested with Python24 vegaseat 21aug2005import timedef print_timing(func): def wr……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2629浏览 211个赞
python常用列表,数组操作范例# experimenting with Python's list# tested with Python23 vegaseat 21feb2005# import module os for method listdir()import os# creat an empty li……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1567浏览 362个赞
wxpython开发的简单的gui计算器# wxCalc1 a simple GUI calculator using wxPython# created with the Boa Constructor which generates all the GUI components# all I had to do is add some code……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2854浏览 1345个赞
从CVS库中迁出项目以后,在目录中含有CVS目录。通过python进行递归删除。由于PYTHON中貌似不能直接删除非空目录,所以先将CVS目录下的文件删除,再删除CVS目录。采用walk方法,递归遍历各目录。来源:http://blog.csdn.net/moxuansheng/article/details/6450687''……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1895浏览 529个赞
python删除过期文件代码片段# remove all jpeg image files of an expired modification date = mtime# you could also use creation date (ctime) or last access date (atime)# os.stat(filename) ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2740浏览 2856个赞
python 对元组对库存进行排序# sort an inventory list by item count# Python24 (needed) modified by vegaseat 10may2005import operator# create an inventory list of tuples# each tuple c……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1889浏览 786个赞
wxPython listbox 使用演示# load a listbox with names, select a name and display in title# experiments with wxPython by vegaseat 20mar2005# Python v2.4 and wxPython v2.5# If yo……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2310浏览 798个赞
python 根据完整路径获得目录名,例如输入c:\\abc\\123.zip ,返回c:\\abcimport osos.path.dirname('c:\\abc\\123.zip') 返回结果:c:\\abc……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1590浏览 2131个赞
python常用字典操作范例# experimenting with the Python dictionary# a seemingly unordered set of key:value pairs, types can be mixed# Python23 tested vegaseat 13feb2005# initia……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1746浏览 2100个赞
模拟C和Pascal的结构体实现的Employee类,可以从cvs文件读取信息并搜索'''Class_StructEmp2_file.pymimic a C Structure or Pascal Record using a classload the data from a csv type file like t……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3193浏览 1361个赞
python 一句话代码将图片变亮或者变暗# do pixel math on an image using the PIL image library# free from: http://www.pythonware.com/products/pil/index.htm# Python23 tested vegaseat 2……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2646浏览 1506个赞
python adslimport osg_adsl_account = {"name": "adsl", "username": "0512...", "password": "..."} class Adsl……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2467浏览 531个赞
python播放wav音频文件# play a wave sound on a Windows Box# Python23 tested vegaseat 2/8/2005import winsoundimport time# pick a wave file supplied by Windows XP or one of your ……继续阅读 » 水墨上仙 5年前 (2021-01-15) 3251浏览 840个赞
通过wxpython编写windows GUI程序这段代码只是一个最简单的范例# using a wx.Frame, wx.MenuBar, wx.Menu, wx.Panel, wx.StaticText, wx.Button, # and a wx.BoxSizer to show a rudimentary wxPython Windows G……继续阅读 » 水墨上仙 5年前 (2021-01-15) 2285浏览 1502个赞
Author:pakoEmail>alk:zealzpc@gmail.com对于服务器的监控来说,监控linux不管是自己动手写脚本还是用一些开源的工具比如nagios,zenoss什么的。但毕竟还是有些公司有windows做服务器的,相对linux来说,windows没有方便的shell,cmd下提供的命令对于监控来说远远没有linux方便……继续阅读 » 水墨上仙 5年前 (2021-01-15) 1636浏览 113个赞
下面的代码通过Tkinter制作windows窗口界面,然后时间了一个简单的倒计时功能,代码可以直接运行# Countdown using Tkinter from Tkinter import *import timeimport tkMessageBoxclass App: def __init__(self,master……继续阅读 » 水墨上仙 5年前 (2021-01-13) 3101浏览 1189个赞
python获得文件扩展名import os.path def file_extension(path): return os.path.splitext(path)[1] ……继续阅读 » 水墨上仙 5年前 (2021-01-13) 2887浏览 977个赞
python通过win32com库播放mp3文件# Python supports COM, if you have the Win32 extensions# check your Python folder eg. D:\Python23\Lib\site-packages\win32com# also http://starship.pyt……继续阅读 » 水墨上仙 5年前 (2021-01-13) 3280浏览 960个赞
python删除整个目录(目录非空),os.rmdir()只能删除空目录,下面的函数可以删除整个非空目录import osimport shutildef CleanDir( Dir ): if os.path.isdir( Dir ): paths = os.listdir( Dir ) for pa……继续阅读 » 水墨上仙 5年前 (2021-01-13) 3243浏览 579个赞
python Image.blend ValueError: images do not matchfrom PIL import Image def blend_two_images(): img1 = Image.open( "bridge.png ") img1 = img1.convert(……继续阅读 » 开心洋葱 6年前 (2020-12-02) 3119浏览 5评论1238个赞
python 通关sleep函数等待到明天再执行def waitToTomorrow(): """Wait to tommorow 00:00 am""" tomorrow = datetime.datetime.replace(datetime.datetime.now……继续阅读 » 水墨上仙 6年前 (2020-11-25) 3385浏览 1872个赞
Python遍历字符串中的每一个字符直接用for 语句#遍历字符串a = 'asd'for q in a: print(q)# 输出结果为asd ……继续阅读 » 水墨上仙 6年前 (2020-11-16) 2395浏览 1840个赞
python旋转图片的代码# rotate an image counter-clockwise using the PIL image library# free from: http://www.pythonware.com/products/pil/index.htm# make sure to install PIL after your……继续阅读 » 水墨上仙 6年前 (2020-11-16) 2647浏览 1746个赞
python 计算字符串长度,一个中文算两个字符,先转换成utf8,然后通过计算utf8的长度和len函数取得的长度,进行对比即可知道字符串内中文字符的数量,自然就可以计算出字符串的长度了。来源:http://www.75271.comvalue=u'脚本12'length = len(value)utf8_length = ……继续阅读 » 水墨上仙 6年前 (2020-11-16) 2322浏览 2437个赞
python从网络端口读取文本数据# To test it with netcat, start the script and execute:# # echo "Hello, cat." | ncat.exe 127.0.0.1 12345#import socketHOST = 'localhos……继续阅读 » 水墨上仙 6年前 (2020-11-16) 1433浏览 908个赞
转自:http://blog.csdn.net/marising/article/details/6551692在很久以前,我写了一个系列,Python和C和C++的交互,如下http://blog.csdn.net/marising/archive/2008/08/28/2845339.aspx目的是解决Python和C/C++的互操作性的问题,假如……继续阅读 » 水墨上仙 6年前 (2020-11-16) 1565浏览 2090个赞
python显示生日是星期几# find the day of the week of a given date# Python will trap impossible dates like (1900, 2, 29)# tested with Python24 vegaseat 01aug2005from datetime i……继续阅读 » 水墨上仙 6年前 (2020-11-16) 2948浏览 774个赞
python比较两段文本的不同之处# find the difference between two texts# tested with Python24 vegaseat 6/2/2005import difflibtext1 = """The World's Shortest Books:……继续阅读 » 水墨上仙 6年前 (2020-11-16) 3257浏览 2434个赞
python获取一组汉字拼音的首字母来源:http://wangwei007.blog.51cto.com/68019/983289作者:lover007#!/usr/bin/env python # -*- coding: utf-8 -*- def multi_get_letter(str_input): if ……继续阅读 » 水墨上仙 6年前 (2020-11-13) 2084浏览 1318个赞
python监控本机cpu的利用百分比情况import wmiimport timec = wmi.WMI()while True: for cpu in c.Win32_Processor(): timestamp = time.strftime('%a, %d %b %Y %H:%M:%S',……继续阅读 » 水墨上仙 6年前 (2020-11-13) 2962浏览 1886个赞
python自动连接ssh的代码#!/usr/bin/python#-*- coding:utf-8 -*-import sys, time, ostry: import pexpectexcept ImportError: print """ You must insta……继续阅读 » 水墨上仙 6年前 (2020-11-13) 1807浏览 2518个赞
下面这段代码意思是,如果b为None则c等于a,否则c=b,用python写起来就容易多了a=100b=50c=a if b is None else bprint(c)#输出结果为50,这段代码相当于if b is None: c = aelse: c = b ……继续阅读 » 水墨上仙 6年前 (2020-11-13) 2801浏览 2071个赞
想sqlite插入一条记录后,马上获得自动生成的id编号的方法connection=sqlite3.connect(':memory:')cursor=connection.cursor()cursor.execute('''CREATE TABLE foo (id integer primary ……继续阅读 » 水墨上仙 6年前 (2020-11-13) 3494浏览 283个赞
此代码主要是为了演示如何通过按钮来更新grid的数据import wx, wx.gridclass GridData(wx.grid.PyGridTableBase): _cols = "a b c".split() _data = [ "1 2 3".split(), ……继续阅读 » 水墨上仙 6年前 (2020-04-13) 2772浏览 382个赞
在python脚本内运行linux命令#/usr/bin/env pythonimport subprocessclass RunCmd(object): def cmd_run(self, cmd): self.cmd = cmd subprocess.call(self.cmd, shell=Tru……继续阅读 » 水墨上仙 7年前 (2019-09-03) 2759浏览 1676个赞
Python输出两个字符串中相同的字符,计算两个字符串的交集import setsmagic_chars = sets.Set('abracadabra')poppins_chars = sets.Set('supercalifragilisticexpialidocious')print '&……继续阅读 » 水墨上仙 7年前 (2019-09-03) 3485浏览 2220个赞