随笔分类 - Python
Python学习笔记、练习 更多见 http://home.cnblogs.com/group/py/
摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-import osdef trimfile(dir): for fn in os.listdir(dir): sfile = os.path.join(dir, fn) if os.path.isdir(sfile): trimfile(sfile) continue if '~' in fn: newfile = os.path.join(dir, fn[1:]) ope...
阅读全文
摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-import os, redef multi_replace(text, adict): rx = re.compile('|'.join(map(re.escape, adict))) def xlat(match): return adict[match.group(0)] return rx.sub(xlat, text)def batrename(curdir, pairs): for fn in os.listdir(curdir): newfn...
阅读全文
摘要:'''Add decorator for each method of a class.'''import functoolsimport threadingclass DecorateClass(object): def decorate(self): for name, fn in self.iter(): if callable(fn): ...
阅读全文
摘要:这是在Python学习小组上介绍的内容,现学现卖、多练习是好的学习方式。 第一步:最简单的函数,准备附加额外功能 # -*- coding:gbk -*-'''示例1: 最简单的函数,表示调用了两次'''def myfunc(): print("myfunc() called.")myfunc()myfunc()第二步:使用装饰函数在函数执行前和执行后分别附加额外功能# -*- c...
阅读全文
摘要:https://github.com/rhcad/x3pySVN: https://github.com/rhcad/x3py.git/trunkGIT: git clonegit://github.com/rhcad/x3py.gitC++插件框架 x3py 在下列平台编译测试通过:1、Win7 x64, VC++ 9.0 x64 | VC++ 8.0 x86, Console | Python2.7/3.2 | Perl5 | Java 1.62、Win7 x64, TDM GCC 4 + MSYS + Makefile, Console | Python | Perl | Java (P
阅读全文
摘要:* Add GetLogObserver() export function in LogWriter.plugin so it can be used by oneself regardless PluginManager. * LogHelper.h: Add X3LOG_GROUP(name) and X3LOG_GROUP2(name, extra). * Add LogHelper2.h for non-plugin projects. * Auto call x3UninitializePlugin() when a plugin is unloading. * Ad...
阅读全文
摘要:1、迭代器简介Python中很多对象都是迭代器,例如列表、元组、字符串、文件、映射、集合。所有可迭代的类必须实现__iter__()函数,得到迭代器对象,通常返回自身(即自身就是迭代器对象);所有的迭代器类都实现了next()函数,当然迭代器类也需要实现__iter__()函数;3.0中是__next__()函数。2、迭代器常见用法用法1: for 变量 in 可迭代对象用法2:if 变量 in 可迭代对象用法3(较少使用):变量 = iter(可迭代对象),然后循环iter.next()得到每个值,直到StopIteration异常出现。如果想重新循环,没有回到开头的函数,可以重新得到迭代器
阅读全文
摘要:为了避免手工创建新的插件工程,同时也是学习python,今天用了6个小时边学边试,终于编写完了。 学习到的新知识有: 1、正则表达式一次替换多种子串 2、遍历创建目录 3、回调函数 4、路径模块 5、字典的一些用法 6、主函数、编写习惯、递进开发方式 #!/usr/bin/env python"""Function: Create a plugin ...
阅读全文
摘要:对一个Win32工程添加x64配置后,宏定义WIN32需要改为_WIN64,Python脚本如下: import osdef replaceprojtext(s, pos, find, replace): if pos > 0 and s.rfind(find) > pos: return (True, s[:pos] + s[pos:].replace(find, repl...
阅读全文
摘要:我在 Win2008 + VS2008 x64下对已有的VC++工程增进了x64编译平台项,这个操作很快,但还需要把x64编译平台项的宏定义由 WIN32 改为 _WIN64,由于涉及19个工程,手工改太累。于是我用了半个小时,现学现用,编写了下面的代码,一下子全搞定了,无论有多少工程都瞬间完成替换。import ospath = r'F:\x3c\projects\msvc\vcproj' '\\'for fn in [path+f for f in os.listdir(path) if f[-7:]=='.vcproj']: s = ope
阅读全文

浙公网安备 33010602011771号