Help with decorators

Mr SZ sk8in_zombi at yahoo.com.au
Fri Jul 18 16:27:10 CEST 2008


Hi,

I'm using decos for the first time.I want to check the input and then call a function in a class.

I'm pasting the code:

    def check_input_sanity(self,rover_input):
        '''Check the input from client'''
        def _check(fn):
            def _inner(rover_input):
                if rover_input[0].upper().replace('L','').replace('R').replace('M') == '' and rover_input[1].upper() in ['N','S','E','W']:
                    print 'Input is sane'    
                    fn()
                return _inner
        return _check            
    
        
   
    @check_input_sanity([self.origorient,self.direction_str,self.init_loc])
    def tell_coord_from_path(self):
        '''Gives the final co-ordinate and the direction untill it falls off/reaches.'''
        pdir = self.origorient #Present direction


here the vars : self.origorient,self.direction_str,self.init_loc are the ones I would like to check for sanity.
But I get an error:

Traceback (most recent call last):
  File "tw.py", line 5, in <module>
    import sys,os,robo
  File "C:\Python25\thought\robo.py", line 30, in <module>
    class robo_actions(robo):
  File "C:\Python25\thought\robo.py", line 58, in robo_actions
    @check_input_sanity([self.origorient,self.direction_str,self.init_loc])
NameError: name 'self' is not defined

Why is this so? aren't they to be referred to by self with in a class as they are attributes of the object ?
" life isn't heavy enough,it flies away and floats far above action"


      Start at the new Yahoo!7 for a better online experience. www.yahoo7.com.au
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080718/89d1bf36/attachment.html>


More information about the Python-list mailing list