Martin von Loewis <loewis at informatik.hu-berlin.de> writes: > def welease_bwian(klasse, N): > klasse.wodger = klasse.bwian[N] Cool, I like this. I guessed I should be able to do something along these lines . . . but it still leaves me with some problems. A call to welease_bwian( woderwick, ... ) incorrectly sets wodger for all the subclasses. ----------------------------------------------------------- def welease_bwian( the_class, N ): the_class.wodger = the_class.bwian[N] class woderwick: bwian = [ 'zero', 'one', 'two', 'many' ] wodger = bwian[0] # default value def __init__ ( self ): print self.wodger class rodrigo(woderwick): bwian = [ 'cero', 'uno', 'dos', 'demasiados' ] class roderich(woderwick): bwian = [ 'gar nichts', 'eins', 'zwei', 'viele' ] class roderik(roderich): # :-) bwian = [ 'geen bal', 'een', 'twee', 'te veel' ] class rafal(woderwick): bwian = [ 'figa z makiem', 'raz', 'dwa', 'kupa' ] # Defaults still don't work a = woderwick() # wnat zero, get zero b = rodrigo() # want cero, get zero # Base class call incorrectly sets subclass wodger welease_bwian( woderwick, 1 ) a = woderwick() # Gives one, as required b = rodrigo() # Gves one, rather than uno welease_bwian( rodrigo, 1 ) c = rodrigo() # Now correctly gives uno, but tedious to do for all subclasses. # Alternatively, requres knowledge of which particular class # I am using (which I don't know how to get).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4