python修改文件名、目录名os.rename("/path/to/old/file", "/path/to/new/file") ……继续阅读 » 水墨上仙 8年前 (2018-10-24) 2673浏览 852个赞
下面列举了TextCtrl的可用样式'''wx.TE_CENTER:控件中的文本居中。wx.TE_LEFT:控件中的文本左对齐。默认行为。wx.TE_NOHIDESEL:文本始终高亮显示,只适用于Windows。wx.TE_PASSWORD:不显示所键入的文本,代替以星号显示。180 / 565wx.TE_PR……继续阅读 » 水墨上仙 8年前 (2018-10-24) 2903浏览 1575个赞
wxpython中的所有文本框都是TextCtrl,不同的形式的文本框通过样式来实现,下面创建了一个密码输入框pwdText = wx.TextCtrl(panel, -1, ”password”, size=(175, -1), style=wx.TE_PASSWORD)……继续阅读 » 水墨上仙 8年前 (2018-10-24) 2452浏览 2526个赞
wxpython的文本框可以在创建时设置样式,下面的例子给文本框设置为制度、富文本编辑、不自动换行等样式style = (wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2 | wx.TE_DONTWRAP)wx.TextCtrl.__init__(self, parent, id, style=style)……继续阅读 » 水墨上仙 8年前 (2018-10-24) 2728浏览 1667个赞
python在控制台输入密码但是不显示import console;namespace console{ //控制台读取密码,并显示星号 getPassword = function(){ var tstr = {}; var input = kbRead(true); while( i……继续阅读 » 水墨上仙 8年前 (2018-10-24) 2016浏览 422个赞
运行这段代码,将生成一个简单的左右结果的框架,非常好用,需要wx.aui模块# -*- coding: cp936 -*-# 2010-04-20 18:40 中国广州天河# 如何实现动态布局# source:http://stackoverflow.com/questions/523363/how-do-i-layout-a-3-pane-wi……继续阅读 » 水墨上仙 8年前 (2018-10-24) 1752浏览 2182个赞
wxpython自带一个列表选择对话框SingleChoiceDialog,可以用一个数组定义要选择的元素列表dlg = wx.SingleChoiceDialog(None,’What version of Python are you using?’, ’Single Choice’,[‘1.5.2’, ’2.0’, ’2.1.3’, ’2.2’,……继续阅读 » 水墨上仙 8年前 (2018-10-24) 2806浏览 1149个赞
python实现的代码行数统计代码''' Author: liupengfei Function: count lines of code in a folder iterativelyShell-format: cmd [dir] Attention: default file encode ……继续阅读 » 水墨上仙 8年前 (2018-10-24) 1550浏览 2783个赞
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xce in position 72:E:\CodeFile\Tensorflow\fast-neural-style-tensorflow>pip install pyyamlCollecting pyyaml……继续阅读 » 开心洋葱 8年前 (2018-04-13) 2714浏览 0评论1336个赞
ValueError: Trying to share variable discriminator/d_h4_lin/Matrix, but specified shape (4608, 1) and found shape (18432, 1).Traceback (most recent call last): File "mai……继续阅读 » 开心洋葱 8年前 (2018-04-10) 2842浏览 0评论1228个赞
SystemError: <class ‘cv2.cascadeclassifier’=””> returned a result with an error setpenCV Error: Parsing error (lbpcascade_animeface.xml(6685): Prelim……继续阅读 » 开心洋葱 8年前 (2018-04-10) 3268浏览 93评论1590个赞
python过滤字符串中不属于指定集合的字符# -*- coding: utf-8 -*-import string# 生成所有字符的可复用的字符串,它还可以作为# 一个翻译表,指明“无须翻译”allchars = string.maketrans('', '')def makefilter(ke……继续阅读 » 水墨上仙 8年前 (2018-01-22) 2880浏览 841个赞
用Python提取url链接中的域名与端口import urllib proto, rest = urllib.splittype("http://www.75271.com/11/12.htm") host, rest = urllib.splithost(rest) print host host, port……继续阅读 » 水墨上仙 8年前 (2018-01-21) 3051浏览 704个赞
python自动修改本机网关的代码#!/usr/bin/python#auto change gateway Created By mickelfengimport osimport random,reg='gateway 192.168.1.'rand=random.randint(1,3)test='……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2696浏览 2931个赞
凡是线性回溯都可以归结为右递归的形式,也即是二叉树,因此对于只要求一个解的问题,采用右递归实现的程序要比回溯法要优美的多。def Test(queen,n): '''这个就不用说了吧,就是检验第n(下标,0-7)行皇后的位置是否合理''' q=queen[n] for i in xrange……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2933浏览 1550个赞
python检查序列seq 是否含有aset 中的项# -*- coding: utf-8 -*-def containsAny(seq, aset): """ 检查序列seq 是否含有aset 中的项 """ for c in seq: if c in ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2828浏览 602个赞
python十进制转二进制,可指定位数# convert a decimal (denary, base 10) integer to a binary string (base 2)# tested with Python24 vegaseat 6/1/2005def Denary2Binary(n): ''……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2373浏览 2282个赞
在python里面excel的简单读写操作我这里推荐使用xlrd(特别是读操作)到http://pypi.python.org/pypi/xlrd 去下载 xlrd库;import xlrd def open_excel(fileName="simple.xls"): try: fileH……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2763浏览 411个赞
用Python实现二分查找#!/usr/bin/env pythonimport sys def search2(a,m): low = 0 high = len(a) - 1 while(low <= high): mid = (low + high)/2 midval ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3272浏览 1376个赞
一行代码实现python字符串反转输出import reastring = 'hello world'revchars = astring[::-1]print(revchars)输出结果dlrow olleh ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3090浏览 2474个赞
python过滤字符串中不属于指定集合的字符的类# -*- coding: utf-8 -*-import setsclass Keeper(object): def __init__(self, keep): self.keep = sets.Set(map(ord, keep)) def __getitem……继续阅读 » 水墨上仙 8年前 (2018-01-19) 2678浏览 483个赞
Python数据库访问公共组件及模拟Http请求模拟Http请求 在请求别人接口时,我们最常使用的是模拟Http请求。在python中有许多方式,我选用了新版的httplib2。有兴趣的可以查看一下其他文档。 # encoding: utf-8__author__ = 'changyang'''……继续阅读 » 开心洋葱 8年前 (2018-01-18) 2788浏览 0评论1082个赞
可以通过easy_install qrcode 安装,也可以到:https://github.com/lincolnloop/python-qrcode 下载简单用法import qrcodeimg = qrcode.make('Some data here')高级用法import qrcodeqr = qrcode.……继续阅读 » 水墨上仙 9年前 (2018-01-10) 2478浏览 475个赞
使用一个循环,不断的创建线程,直到出现异常,才通知它们。python真是个好东西。#!/usr/bin/env python #coding=gbk import threading import time, random, sys class Counter: def __init__(self):……继续阅读 » 水墨上仙 9年前 (2018-01-09) 2533浏览 2735个赞
python实现的守护进程(Daemon)def createDaemon(): ”’Funzione che crea un demone per eseguire un determinato programma…”’ import os # create - fork 1 try: ……继续阅读 » 水墨上仙 9年前 (2018-01-09) 2592浏览 2162个赞
Perl批量执行Linux安装程序和脚本#!/usr/bin/perl#use Cwd;sub ExecuteAll(){ local($dir) = @_; opendir(DIR,"$dir"|| die "can't open $dir"); local @files =rea……继续阅读 » 水墨上仙 9年前 (2018-01-09) 1987浏览 2318个赞
python提取url中的域名和端口号import urllib proto, rest = urllib.splittype("http://www.75271.com/11/12.htm") host, rest = urllib.splithost(rest) print host host, port =……继续阅读 » 水墨上仙 9年前 (2018-01-09) 2712浏览 2536个赞
来源:http://blog.csdn.net/sun7545526/article/details/8138603需求:设计一个”石头,剪子,布”游戏,有时又叫”Rochambeau”,你小时候可能玩过,下面是规则.你和你的对手,在同一时间做出特定的手势,必须是下面一种手势:石头,剪子,布.胜利者从下面的……继续阅读 » 水墨上仙 9年前 (2018-01-09) 2035浏览 858个赞
python检查一个集合是否包含了另外一个集合的所有项>>> L1 = [1, 2, 3, 3]>>> L2 = [1, 2, 3, 4]>>> set(L1).difference(L2)set([ ])>>> set(L2).difference(L1)set(……继续阅读 » 水墨上仙 9年前 (2018-01-09) 3308浏览 1968个赞
python字符串按单词反转输出方法1import reastring = 'hello world'revwords = ' '.join(reversed(astring.split()))print(revwords)方法2import reastring = 'hello ……继续阅读 » 水墨上仙 9年前 (2018-01-09) 3381浏览 2949个赞
python通过正则获取网页上的全部链接import re, urllibhtmlSource = urllib.urlopen("http://www.75271.com").read(200000)linksList = re.findall('<a href="(.*?)">.*?……继续阅读 » 水墨上仙 9年前 (2018-01-09) 3233浏览 2381个赞
python plt.show 关闭在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0.1版本才支持多个show()的使用。想在显示图像后继续运行相关的处理命令,或者显示一副图像后关闭它,再显示第二幅图像。如下办法:plt.close() will close current inst……继续阅读 » 开心洋葱 9年前 (2018-01-09) 3048浏览 0评论2693个赞
Python获取CPU使用率、内存使用率、网络使用状态注:需要安装psutil库#!/usr/bin/env python## $Id: iotop.py 1160 2011-10-14 18:50:36Z g.rodola@gmail.com $## Copyright (c) 2009, Jay Loden, Giampaolo Ro……继续阅读 » 水墨上仙 9年前 (2018-01-08) 1747浏览 354个赞
python通过代理服务器访问ftp服务import urllib2# Install proxy support for urllib2proxy_info = { 'host' : 'proxy.myisp.com', 'port' : 3128, ……继续阅读 » 水墨上仙 9年前 (2017-07-11) 2129浏览 1787个赞
python3 压缩文件夹内的文件到zip'''Created on Dec 24, 2012将文件归档到zip文件,并从zip文件中读取数据@author: liury_lab'''# 压缩成zip文件from zipfile import * #@UnusedWil……继续阅读 » 水墨上仙 9年前 (2017-07-11) 2730浏览 710个赞
python返回指定日期是一年中的第几周>>> import datetime>>> print datetime.datetime(2006,9,4).isocalendar()[1]36 ……继续阅读 » 水墨上仙 9年前 (2017-07-11) 2790浏览 201个赞
d157e0d7f137c9ffc8d65473e038ee86 是 “Hello world !” 使用 “mykey”作为key的签名结果>>> import hmac>>> print hmac.new("mykey","Hello ……继续阅读 » 水墨上仙 9年前 (2017-07-04) 1714浏览 1793个赞
本代码运行后会减轻8088端口,用户访问:http://127.0.0.1:8088 或输出html代码:Hello World!#!/usr/bin/pythonimport BaseHTTPServerclass MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(……继续阅读 » 水墨上仙 9年前 (2017-07-04) 2584浏览 1165个赞
python读取文件同时输出行号和内容file = open('file.txt','r')for (num,value) in enumerate(file): print "line number",num,"is:",valuefile.close()……继续阅读 » 水墨上仙 9年前 (2017-07-03) 1662浏览 2065个赞
python实现简单的soap客户端# $Id: testquote.py 2924 2006-11-19 22:24:22Z fredrik $# delayed stock quote demo (www.xmethods.com)from elementsoap.ElementSOAP import *class QuoteService……继续阅读 » 水墨上仙 9年前 (2017-07-03) 1856浏览 369个赞
python 递归搜索文件夹下的指定文件import osdef look_in_directory(directory): """Loop through the current directory for the file, if the current item is a directory……继续阅读 » 水墨上仙 9年前 (2017-07-03) 2922浏览 2166个赞
python读取LDIF文件#!/usr/bin/python# -*- coding: iso-8859-1 -*-import ldif # ldif module from http://python-ldap.sourceforge.netclass testParser(ldif.LDIFParser): def __in……继续阅读 » 水墨上仙 9年前 (2017-06-15) 2020浏览 2788个赞
python获取一组数据里的最大值max函数使用演示# 最简单的max(1, 2)max('a', 'b')# 也可以对列表和元组使用max([1,2])max((1,2))# 还可以指定comparator functionmax('ah', 'bf……继续阅读 » 水墨上仙 9年前 (2017-06-15) 2934浏览 2870个赞
zip可以对元组进行元素对应重组,返回一个新的元组数组>>> print zip( ['a','b','c'], [1,2,3] )[('a', 1), ('b', 2), ('c', 3)]>>&g……继续阅读 » 水墨上仙 9年前 (2017-06-15) 1884浏览 193个赞
如果你有一个表格,想把行和列进行互换,这段python代码帮你实现,超简单table = [ ('Person', 'Disks', 'Books'), ('Zoe' , 12, 24 ), ('……继续阅读 » 水墨上仙 9年前 (2017-06-09) 3208浏览 1797个赞