Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One way is to create properties for each of them:</p> <pre><code>@property def param_1(self): return self.big_parameter_group.small_parameter_group.param_1 @property def param_2(self): return self.big_parameter_group.small_parameter_group.param_2 @property def param_2(self): return self.big_parameter_group.small_parameter_group.param_2 </code></pre> <p>Another more robust but less explicit way would be to override the <strong>getattr</strong> method like so:</p> <pre><code>def __getattr__(self, name): import re p = re.compile('param_[0-9]+') if p.match(name): return getattr(self.big_parameter_group.small_parameter_group, name) else: return super(MyClass, self).__getattr__(name) </code></pre> <p>This will work for any property that matches the format specified by the regex (<code>param_</code>[some number])</p> <p>Both of these methods will allow you to call <code>self.param_1</code> etc, but it's just for retriving. If you want to set the attributes you'll need to also create a setter:</p> <pre><code>@param_1.setter def param_1(self, value): print 'called setter' self.big_parameter_group.small_parameter_group.param_1 = value </code></pre> <p>Or to complement <code>getattr</code>:</p> <pre><code>def __setattr__(self, name, value): import re p = re.compile('param_[0-9]+') if p.match(name): return setattr(self.big_parameter_group.small_parameter_group, name, value) else: return super(MyClass, self).__setattr__(name, value) </code></pre> <p>(Haven't tested these out so there may be typos but the concept should work)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload