Code redundancy

Alan Harris-Reid aharrisreid at googlemail.com
Wed Apr 21 01:00:17 CEST 2010


Xavier Ho wrote:
> On Wed, Apr 21, 2010 at 7:59 AM, Alan Harris-Reid 
> <aharrisreid at googlemail.com <mailto:aharrisreid at googlemail.com>> wrote:
>
>     The code is not usually in class.__init__ (otherwise I would have
>     used the self. prefix)
>
>
> Alan, if your variables are not usually in __init__, what's preventing 
> you from using class variables like this:
>
> >>> class Test():
> ...     something = 1
> ...     more = 2
> ...    
> >>> Test.more
> 2
>
> What's your use case?
>
> Cheers,
> Xav
Hi Xavier, thanks for the reply,

In this case I am setting attributes of an instantiated class, so the 
original class might go something like

class Test
    attr1 = some default value
    attr2 = another default value
    attr3 = yet another default value
    etc.

and the instantiated class might go something like

Test2 = Test()
Test2.attr1 = runtime value
Test2.attr2 = another runtime value
etc.

Regards,
Alan




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100421/7004b429/attachment.html>


More information about the Python-list mailing list