what is the difference between @property and method

2012-02-09 Thread Zheng Li
class A(object):
@properymethod
def value1(self):
 return 'value1'

def value2(self):
return 'value2'

what is the difference between value1 and value2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is the difference between @property and method

2012-02-10 Thread Zheng Li
Thank you

On 2012/02/10, at 0:36, John Posner wrote:

> On 2:59 PM, Devin Jeanpierre wrote:
> 
> 
>> It is kind of funny that the docs don't ever explicitly say what a
>> property is. http://docs.python.org/library/functions.html#property --
>> Devin 
> 
> Here's a writeup that does:
> http://wiki.python.org/moin/AlternativeDescriptionOfProperty
> 
> -John
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


how to tell a method is classmethod or static method or instance method

2012-02-12 Thread Zheng Li
how to tell a method is class method or static method or instance method?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to tell a method is classmethod or static method or instance method

2012-02-13 Thread Zheng Li

I can get "method1" of class "Test" by
a = getattr(Test, "method1")

and I also want know how to invoke it
a() or  a(Test())



BTW:
I don't see what the problem is if I ask a question just because I am curious 
about it.


On 2012/02/13, at 16:23, Cameron Simpson wrote:

> On 13Feb2012 15:59, Zheng Li  wrote:
> | how to tell a method is class method or static method or instance method?
> 
> Maybe a better question is:
>  under what circumstances do you need to figure this out? 
> 
> I'm actually quite serious here. Please outline what circumstances cause
> you to want to ask and answer this question.
> 
> Cheers,
> -- 
> Cameron Simpson  DoD#743
> http://www.cskk.ezoshosting.com/cs/
> 
> Reason #173 to fear technology:
> 
>o   o   o   o   o   o  
>   ^|\ ^|^ v|^ v|v |/v |X|  \|  |
>/\  >\ /<   >\ /<   >\ /<   >\
> 
>o>  o   o   o   o   o   o   o
>\   x<\> <)>  |\
>   /<   >\ /<   >\ /<   >\  >>  L
> 
> Mr. email does the Macarena.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to tell a method is classmethod or static method or instance method

2012-02-14 Thread Zheng Li
thank you.

I know the second way works.

but in my case, i need "method1" to be a class method, because I use it to 
create an object.

I have a lot of classes that have "__init__" with 2 arguments -- self, and user 
id.
usually, "SomeClass(user_id)" is used to create an object of "SomeClass", 
but if "SomeClass" has a class method named "method1", "method1" will be used 
to finish the job.

and i get it. the context is useful.


On 2012/02/14, at 18:52, Cameron Simpson wrote:

> On 14Feb2012 13:13, Zheng Li  wrote:
> | > On 13Feb2012 15:59, Zheng Li  wrote:
> | > | how to tell a method is class method or static method or instance 
> method?
> | > 
> | > Maybe a better question is:
> | >  under what circumstances do you need to figure this out? 
> |
> | I can get "method1" of class "Test" by
> | a = getattr(Test, "method1")
> | 
> | and I also want know how to invoke it
> | a() or  a(Test())
> 
> Normally:
> 
>  a(T)
> 
> where T is an object of type/class Test. So your second approach is
> notionally correct (aside from making a throwaway object that is then
> discarded).
> 
> | BTW:
> | I don't see what the problem is if I ask a question just because I am 
> curious about it.
> 
> There's nothing wrong with it at all.
> 
> But often, questions arise from some other circumstances and this one is
> of such a flavour that if you wanted this code in a real application it
> would _often_ be the wrong solution to seek, because normally you know
> how to call something - it is not normally useful to introspect it to
> decide what to do.
> 
> So I was wondering what the outer context might be, because there may
> well have been a better solution to the situation that brought up the
> specific question.
> 
> Simple curiosity is sufficient reason, of course.
> -- 
> Cameron Simpson  DoD#743
> http://www.cskk.ezoshosting.com/cs/
> 
> Too young to rest on the weekend, too old to rest during the week.
>- Mark Randol 

-- 
http://mail.python.org/mailman/listinfo/python-list


question about function pointer

2012-02-16 Thread Zheng Li
def method1(a = None):
print a

i can call it by
method1(*(), **{'a' : 1})

I am just curious why it works and how it works?
and what do *() and **{'a' : 1} mean?

when I type *() in python shell, error below happens

  File "", line 1
*()
^
SyntaxError: invalid syntax

-- 
http://mail.python.org/mailman/listinfo/python-list