# -*- coding: utf-8 -*-
#!/usr/bin/env python
def spamrun(fn):
def sayspam(*args):
print "spam,spam,spam "
fn(*args)
return
return sayspam
@spamrun
def useful(a,b):
print a**2+b**2
useful(3,4)
def myDeco(args):
print("Hello ,I'm Decorator!")
print("args:",args) #处理参数
def _myDeco(func):#处理函数
def __myDeco(*args,**kwargs): #处理函数的参数
print ("function name: %s " % (func.__name__) )
ret = func(*args,**kwargs)
return ret
return __myDeco
return _myDeco
@myDeco("my_name")
def run(a,b):
print("func run start:")
print("---------------")
print("run(%s,%s)" % (a,b))
print("---------------")
print("func run end")
run(1,2)
class myDecorator(object):
def __init__(self, fn):
print "inside myDecorator.__init__()" , fn.__name__
self.fn = fn
def __call__(self,*args):
self.fn(args)
print "inside myDecorator.__call__()" ,args[0],args[1],args[2]
@myDecorator
def aFunction(a=0,b=0,c=0):
print "inside aFunction()"
print "Finished decorating aFunction()"
aFunction(1,2,3)
分享到:
2014-12-02 17:30
浏览 514
评论
1 楼
白云天
2014-12-04
开发命名规范
工程格式:
所有代码都小写,如果使用中文开发,所有界面与Python代码都要使用中文,通过导出翻译文件可以制作其它语言包。
ws_project[文件夹]
----------- controllers[存放外部地址接口文件夹]
--------------------------- main.py[外部地址接口py文件]
------------data[初启化模块的数据的文件夹]
-------------------date.xml[初启化模块的数据]
-------------------date_base.xml[初启化模块底层数据]
------------demo[测试数据文件夹]
-------------------model_demo.xml[测试数据]
------------doc[开发特性文件夹文档]
-----------------index.rst[功能与注意事项说明]
-----------------changelog.rst[版本升级日志]
-----------------stage_status.rst[开发阶段]
------------edi[外部数据交换接口文件夹]
-----------------model.py[外部数据交换接口文件夹]
-----------------model_edi.xml[外部数据交换接口文件夹]
------------i18n[翻译文件夹]
------------------ zh_CN.po[中文翻译包]
------------------ zh_TW.po[繁体翻译包]
------------------ en_US.po[英文翻译包]
------------models[继承对象修改文件夹]
------------report[报表模块文件夹]
---------------------model_report.xml[报表数据格式]
---------------------model _report_template.xml[报表引用模板]
------------security[权限设计文件夹]
-------------------------model_security.xml[权限组与过渡规则]
-------------------------ir.model.access.csv[对象权限]
------------static[静态文件引用文件夹]
--------------------description[APP描述文件夹]
------------------------------------icon.png[APP图标]
------------------------------------index.html[APP模块介绍]
--------------------src[基础引用]
--------------------------css[Qweb引用样式文件夹]
--------------------------img[Qweb图片文件夹]
--------------------------js[Qweb JS文件夹]
--------------------------xml[Qwe 界面定义文件夹]
------------templates[静态文件模板文件夹]
------------test[测试文件夹]
------------tests[测试用类文件夹]
------------views[Qweb界面文件夹]
------------wizard[向导文件夹]
------------README.md[模块功能说明]
------------base.xml[用于存放公共的信息如顶层菜单]
------------sequence.xml[用于存放自动号规则]
------------report_qweb_view.xml[定义报表菜单]
------------model_workflow.xml[定义工作流]
总结:
原单上一个model 对应一个model_view.xml,但如果这个对象引用在其它的类中可以不建对应的类文件与视图文件。
Py内容命名规则
class model (osv. Model):
_name = " ws.qr.code"
方法取值前缀使用下划线
def _all_function(self, cr, uid, ids, field_name, arg, context=None):
按钮 button name后台使用
def but_ state (self, cr, uid, ids, context=None):
XML ID命名