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() ##调用函数对象
相关文档:
二进制文件下载地址:
SinaGetBook
效果如图:
代码:
#!/usr/bin/env python
#coding=utf-8
#!/usr/bin/env python
#coding=utf-8
import traceback
import sys
import wx
import re
import urllib
import wx.richtext as rt
import wx.lib.buttonpanel as bp
import Casing
import Debug
def trace_back ......
$ 字符串的末尾
^ 字符串的开始
\b 字符的边界
前缀t 字符串中的反斜线(所有字符)不转义
? 可选地匹配(位于之前的)单个字符
() 改变优先级,作为一个整体,一个组
| 或者
(A|B) 精确匹配A或B中的一个
{n,m} 匹配(位于之前的字符)n到m次
VERBOSE ......
1. 打印变量和变量自显
>>> myString = 'Hello World!'
>>> print myString
Hello World!
>>> myString
'Hello World!'
因为: print 语句调用str()函数显示对象,而交互式解释器则调用repr()函数来显示对象
sys.stdout.write('hello')不会在末尾加上'\n',而print会
2. 打印文件
hand ......
Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.
There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various man ......
#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
def index(request, pagename=""):
"""显示正常页面,对页面的文字做特殊的链接处理"""
......