关于属性 类属性实际上上包括数据属性和非数据属性(也就是函数),大家都知道他们是分开的,也就是是用方法来控制数据属性,今天我给大家展示一下这方便的高级的应用。 怎么样来获取一个随机数呢,很简单,调用random里的函数就是了。可是我下面就向大家展示关于今天的主角:属性。 例子-1:(设定一个可以自动变化的类属性) -----------------------------------------------------------------------------------> import o...
by wojiaohesen - Python - 2009-06-19 08:20:20 阅读(2698) 回复(7)
python provides a feasible way to define static method in class called staticmethod, just as following code: class MyClass: @staticmethod def Hello(name): print "Hello, %s" % (name) The "@staticmethod" form is a function decorator used to denote the function Hello will act as a static method for class MyClass. Now you can call the method Hello with two ways, MyClass.Hello("...
代码如下
[code]
#include
单独的python程序文件如何使用getattr(obj,attribute)类似的方法去改变全局变量? 最近在写一个小工具程序只有一个程序文件 ,要完成这样一个工作, 举例说明: 两个全量变量 FundType[] SourceType[] 一个文本文件内容为 1,FundType 2,SourceType 3,FundType 4,SourceType 目标是根据文本文件第二栏的名字设置对应全局变量的值 >>>FundType ['1','3'] >>>SourceType ['2','4'] 当然用很多个if - else是可以完成的,但是PHP,...
//源文件test_attribute.c extern void myprint(const char *format,...) __attribute__((format(printf,1,2))); void test() { myprint("i=%d\n",6); myprint("i=%s\n",6); myprint("i=%s\n","abc"); myprint("%s,%d,%d\n",1,2); } int main(int argc,char **argv) { test(); } //编译test_attribute.c arm-uclinux-gcc -DDEBUG -Wall -Os -fstrict-aliasing -msoft-float -march=armv5 - ...
最近在作代码移植的时候发现有这样的代码: int i attribute_unused; 请大家帮我看看这是啥意思,谢谢了! ps:我在网上查说是防止编译时候warning的,但是具体的就不清楚了.