易截截图软件、单文件、免安装、纯绿色、仅160KB

Python中静态方法的实现

作者:老王
Python似乎很讨厌修饰符,没有常见的static语法。其静态方法的实现大致有以下两种方法:
第一种方式(staticmethod):
>>> class Foo:
        str = "I'm a static method."
        def bar():
            print Foo.str
        bar = staticmethod(bar)
>>> Foo.bar()
I'm a static method.
第二种方式(classmethod):
>>> class Foo:
        str = "I'm a static method."
        def bar(cls):
            print cls.str
        bar = classmethod(bar)
>>> Foo.bar()
I'm a static method.
---------------------------------------------------------------
上面的代码我们还可以写的更简便些:
>>> class Foo:
        str = "I'm a static method."
        @staticmethod
        def bar():
            print Foo.str
>>> Foo.bar()
I'm a static method.
或者
>>> class Foo:
        str = "I'm a static method."
        @classmethod
        def bar(cls):
            print cls.str
>>> Foo.bar()
I'm a static method.
OK,差不多就是这个样子了。


相关文档:

Python内部的线程实现

在Python中的线程运行实际是受到Interpreter的控制或者说牵制的。在Interpreter的核心函数
PyObject * PyEval_EvalFrameEx
(PyFrameObject *f, int
throwflag)
我们可以看到有一个全局变量_Py_Ticker来控制着线程对Interpreter的占有的,默认是Interpreter每执行一百条指令就会释放另一个全局变量interpreter_lock.
......

python join的用法

>>> a="abcd"
>>> ",".join(a)
'a,b,c,d'
>>> "|".join(['a','b','c'])
'a|b|c'
>>> ",".join(('a','b','c'))
'a,b,c'
>>> ",".join({'a':1,'b':2,'c':3})
'a,c,b' ......

vc中调用python代码

运行一句python命令
对vc设置路径
include:D:\PYTHON31\INCLUDE
lib:D:\PYTHON31\LIBS
#include "stdafx.h"
#include "python.h"
int main(int argc, char* argv[])
{
 Py_Initialize() ;
 PyRun_SimpleString("print('Hello')");
 //PyRun_SimpleString("print(dir())");
 Py_Finalize();& ......

python 脚本 - 自动检测代理速度

这个脚本是在 python 环境下使用的,改的网上的一个脚本,可以检测代理中国(www.proxycn.com)上的HTTP代理列表,你也可以自己去上面找列表检测 代码: #!/usr/bin/python # -*- coding: utf-8 -*- # from: ubuntu.org.cn Copyright: GPLv2 import urllib import re from datetime import datetime import socket def fin ......

zz使用 Python 分离中文与英文的混合字串

使用 Python 分离中文与英文的混合字串
LiYanrui

posted @ 大约 1 年前
in 程序设计
with tags
python

, 614 阅读


这个问题是做 MkIV 预处理程序
时搞定的,就是把一个混合了中英文混合字串分离为英文与中文的子字串,譬如,将 ”我的 English 学的不好
&ld ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号