-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Closed
Description
eg: the following DOES NOT WORK for %paste
class SQLFORM_aug: '''Adds buttons to an SQLFORM''' # http://www.swaroopch.com/notes/python_en-object_oriented_programming/ # class variables [no self.] b1=IMG(_src=URL('static/images','heart-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], 'suggestions');")) b2=IMG(_src=URL('static/images','d_arrow-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], 'suggestions');")) buttonList = XML(CAT(b1,b2)) def __init__(self, theSqlform): # instance variables self.theSqlform = theSqlform self.addThebuttons() def addThebuttons(self): '''Adds the buttons to the SQLFORM''' f = self.theSqlform for itm in f.elements()[0][0]: #print itm, '\n\n' itm[2].insert(-1, SQLFORM_aug.buttonList) #print itm[2], '\n\n' def show(self): f = self.theSqlform for itm in f.elements()[0][0]: print itm, '\n\n' In [8]: %paste class SQLFORM_aug: '''Adds buttons to an SQLFORM''' # http://www.swaroopch.com/notes/python_en-object_oriented_programming/ # class variables [no self.] b1=IMG(_src=URL('static/images','heart-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], 'su ggestions');")) b2=IMG(_src=URL('static/images','d_arrow-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], ' suggestions');")) buttonList = XML(CAT(b1,b2)) def __init__(self, theSqlform): # instance variables self.theSqlform = theSqlform self.addThebuttons() def addThebuttons(self): '''Adds the buttons to the SQLFORM''' f = self.theSqlform for itm in f.elements()[0][0]: #print itm, '\n\n' itm[2].insert(-1, SQLFORM_aug.buttonList) #print itm[2], '\n\n' def show(self): f = self.theSqlform for itm in f.elements()[0][0]: print itm, '\n\n' ## -- End pasted text -- --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) C:\web2py\applications\tabledesign\models\003tud.py in () ----> 1 get_ipython().magic(u'paste') C:\Python27\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s) 2134 magic_name, _, magic_arg_s = arg_s.partition(' ') 2135 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) -> 2136 return self.run_line_magic(magic_name, magic_arg_s) 2137 2138 #------------------------------------------------------------------------- C:\Python27\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line) 2060 args.append(sys._getframe(stack_depth).f_locals) 2061 with self.builtin_trap: -> 2062 result = fn(*args) 2063 return result 2064 C:\Python27\lib\site-packages\IPython\frontend\terminal\interactiveshell.py in paste(self, parameter_s) C:\Python27\lib\site-packages\IPython\core\magic.py in (f, *a, **k) 189 # but it's overkill for just that one bit of state. 190 def magic_deco(arg): --> 191 call = lambda f, *a, **k: f(*a, **k) 192 193 if callable(arg): C:\Python27\lib\site-packages\IPython\frontend\terminal\interactiveshell.py in paste(self, parameter_s) 287 write("## -- End pasted text --\n") 288 --> 289 self.store_or_execute(block, name) 290 291 # Class-level: add a '%cls' magic only on Windows C:\Python27\lib\site-packages\IPython\frontend\terminal\interactiveshell.py in store_or_execute(self, block, name) 150 """ Execute a block, or store it in a variable, per the user's request. 151 """ --> 152 b = self.cleanup_input(block) 153 if name: 154 # If storing it for further editing C:\Python27\lib\site-packages\IPython\frontend\terminal\interactiveshell.py in cleanup_input(self, block) 137 lines = block.splitlines() 138 if len(lines) == 1: --> 139 final_blocks.append(self.shell.prefilter(lines[0])) 140 else: 141 final_blocks.append(block) C:\Python27\lib\site-packages\IPython\core\prefilter.py in prefilter_lines(self, lines, continue_prompt) 358 for lnum, line in enumerate(llines) ]) 359 else: --> 360 out = self.prefilter_line(llines[0], continue_prompt) 361 362 return out C:\Python27\lib\site-packages\IPython\core\prefilter.py in prefilter_line(self, line, continue_prompt) 325 if not stripped: 326 if not continue_prompt: --> 327 self.shell.displayhook.prompt_count -= 1 328 329 return normal_handler.handle(line_info) AttributeError: can't set attribute In [9]:
The following DOES work:
class SQLFORM_aug: '''Adds buttons to an SQLFORM''' # http://www.swaroopch.com/notes/python_en-object_oriented_programming/ # class variables [no self.] b1=IMG(_src=URL('static/images','heart-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], 'suggestions');")) b2=IMG(_src=URL('static/images','d_arrow-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], 'suggestions');")) buttonList = XML(CAT(b1,b2)) def __init__(self, theSqlform): # instance variables self.theSqlform = theSqlform self.addThebuttons() def addThebuttons(self): '''Adds the buttons to the SQLFORM''' f = self.theSqlform for itm in f.elements()[0][0]: #print itm, '\n\n' itm[2].insert(-1, SQLFORM_aug.buttonList) #print itm[2], '\n\n' def show(self): f = self.theSqlform for itm in f.elements()[0][0]: print itm, '\n\n' In [6]: %paste class SQLFORM_aug: '''Adds buttons to an SQLFORM''' # http://www.swaroopch.com/notes/python_en-object_oriented_programming/ # class variables [no self.] b1=IMG(_src=URL('static/images','heart-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], 'su ggestions');")) b2=IMG(_src=URL('static/images','d_arrow-v-small.jpg'),_alt='test',_onclick=XML("ajax('month_selector', ['month'], ' suggestions');")) buttonList = XML(CAT(b1,b2)) def __init__(self, theSqlform): # instance variables self.theSqlform = theSqlform self.addThebuttons() def addThebuttons(self): '''Adds the buttons to the SQLFORM''' f = self.theSqlform for itm in f.elements()[0][0]: #print itm, '\n\n' itm[2].insert(-1, SQLFORM_aug.buttonList) #print itm[2], '\n\n' def show(self): f = self.theSqlform for itm in f.elements()[0][0]: print itm, '\n\n' ## -- End pasted text -- In [7]: test() Table P: ...