Welcome‎ > ‎

Class and def scope

Just to show the scope of def's defined AFTER a class, but used in the class:
$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Test:
...     def __init__( self, t1 ):
...             self.t = ft( t1 )
...     def get( self ):
...             print self.t
... 
>>> def ft( t ):
...     return "*" + str( t )
... 
>>> test = Test( "abc" )
>>> test.get()
*abc
>>> 
Comments