how to use @ in python.. and the @property and the @classmethods

Posted by zjm1126 on Stack Overflow See other posts from Stack Overflow or by zjm1126
Published on 2010-04-28T01:50:58Z Indexed on 2010/04/28 2:43 UTC
Read the original article Hit count: 249

Filed under:

this is my code:

def a():
    print 'sss'

@a()
def b():
    print 'aaa'

b()

and the Traceback is:

sss
Traceback (most recent call last):
  File "D:\zjm_code\a.py", line 8, in <module>
    @a()
TypeError: 'NoneType' object is not callable

so how to use the '@'

thanks

updated

class a:
    @property
    def b(x):
        print 'sss'

aa=a()
print aa.b

it print :

sss
None

how to use @property

thanks

updated2

and the classmethods:

class a:
    @classmethods
    def b(x):
        print 'sss'

aa=a()
print aa.b

the Traceback is :

Traceback (most recent call last):
  File "D:\zjm_code\a.py", line 5, in <module>
    class a:
  File "D:\zjm_code\a.py", line 6, in a
    @classmethods
NameError: name 'classmethods' is not defined

© Stack Overflow or respective owner

Related posts about python