thanks, it works!

Anthony於 2016年1月22日星期五 UTC+8上午7時02分36秒寫道:
>
> You have defined __name as a class attribute, so it belongs to the class, 
> not to individual instances of it. Instead, just use self.__name if you 
> want the name to be associated with a particular instance of the class.
>
> Anthony
>
> On Thursday, January 21, 2016 at 5:24:00 PM UTC-5, killzane wrote:
>>
>> I write a class in modules, and create instance in controller.
>> But whatever I create different variable, they point to same instance.
>> May I create new instance when page reload?
>>
>> here is the class
>> # -*- coding: utf-8 -*-
>> from gluon import current
>>
>> class Project:
>> __name = None
>>
>> def __init__(self, id):
>> db = current.db
>> project = db(db.project.id == id).select().first()
>> self.__name = project.name
>> @classmethod
>> def setName(cls, name):
>> cls.__name = name
>> pass
>> @classmethod
>> def getName(cls):
>> return cls.__name
>> pass
>>
>> and here is the controller
>> def classTest():
>>     myObj = Project(5)
>>     myObj2 = Project(4)
>>     # myObj2.setName("abcxxx")
>>     # myObj.setName("defxxx")
>>     return myObj2.getName()
>>
>> whatever I return myObj.name or myObj2.name the answer is "defxxx".
>> so how could I do for it?
>>
>> thanks.
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to