Home > python, Uncategorized > don’t miss inheriting object when using python @property

don’t miss inheriting object when using python @property

Following code looks fine when using python property:

 

class SomeClass():
    @property
    def this( self ):
        return self._hidden_variable * 2
    @this.setter
    def this( self, value ):
        self._hidden_variable = float(value) / 2

 

But the following code would not produce correct result. You must have to inherit object inside SomeClass.

class SomeClass():

has to be changed to

class SomeClass(object):

 

 

 

Advertisements
Categories: python, Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: