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

Python 中的函数调用(类似c中的使用函数入口地址)

def login():
    print 'login'
def logout():
    print 'logout'
controllers = {
'in': login,                                                ##(类似c中的:使用函数入口地址作为字典的值)
'out':logout,
}
def dispatcher(url, controllers):
    func = controllers.get(url, None)         ##(类似c中的:将函数入口指针赋给func)
    if func:
        func()                                              ##(类似c中的:这里通过函数入口指针调用函数)
    else:
        print 'Wrong url!'
dispatcher('in',controllers)
dispatcher('out',controllers)
dispatcher('23',controllers)
结果 :
login
logout
Wrong url!
 ---------------------------------------------------------------------------------------------------------
Python中函数是个对象,所以也是和其他对象一样的使用。
def f1():   ##声明了一个函数对象
    pass
a=f1        ##把函数对象f1赋给a
print a
print f1    ##结果相同 (都指向同一个地址)
f1()         ##调用函数对象
a()          ##调用函数对象


相关文档:

Python嵌入C++详解(3)

继前篇《Import Module》(http://blog.csdn.net/xiadasong007/archive/2009/09/02/4512797.aspx),继续分析嵌入部分基础知识。这次不多说,有什么问题记得多查英文资料,国内的这方面知识少
还是来看代码,写完我就睡觉了~
 
#include "python/python.h"
#include <iostream>
using namespace std;
int ......

Python 温故而知新

1. 打印变量和变量自显
>>> myString = 'Hello World!'
>>> print myString
Hello World!
>>> myString
'Hello World!'
因为: print 语句调用str()函数显示对象,而交互式解释器则调用repr()函数来显示对象
sys.stdout.write('hello')不会在末尾加上'\n',而print会
2. 打印文件
hand ......

Python: 使用装饰器“@”取得函数执行时间

  Python中可以使用装饰器对函数进行装饰(或说包装),利用这个特性,可以很方便、简洁地解决一些问题,比如获得函数执行时间的问题。
  首先,我们定义一个函数,如下:
  def exeTime(func):
def newFunc(*args, **args2):
t0 = time.time()
print "@%s, {%s} start" % (time.strftime("%X", time.local ......

Python 定时运行脚本

import sys
import os
import datetime
import time
class ArgsDealwith:
   
    def arg_environment(self, args):
        filepath = ('PYTHON_PATH', 'path')
        for i in filepath:
 &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号