# Python @property and @setterName.setter

**URL:** <https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278>\
**Category:** Ignition\
**Created:** [October 25, 2016, 1:26pm UTC](https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278 "2016-10-25T13:26:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thosey](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@thosey](https://forum.inductiveautomation.com/u/thosey)\
**Post date:** [October 25, 2016, 1:26pm UTC](https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278/1 "2016-10-25T13:26:04Z")

</div>

I am writing a python class and wish to use getters and setters. I am unsure why this is failing with the object has no attribute ‘setter’. Was this not implemented in Jython?

Ignition platform is trial V 7.8.3

Class code  
``

# Test Class

class Test(object):  
‘Common base class for all test objects’  
# Hidden variable  
\_\_iCount = 0  
# Instantiate the class.  
def **init** (self):  
self.\_\_iCount += 1  
def **del** (self):  
print class\_name, “destroyed”

```
# Class Methods.	
def count(self):
	return self.__iCount
@property	
def myProp(self):
	return self.__x
@myProp.setter	
def myProp(self, value):
	self.__x = value

```

calling code  
`
test = project.hosey.classes.Test()
test.myProp(12)
print test.myProp()
`

ERROR [ActionAdapter-AWT-EventQueue-2] Error executing script for event:&nbsp;`actionPerformed`  
on component:&nbsp;`Button 1`.  
Traceback (most recent call last):  
File “event:actionPerformed”, line 1, in   
ImportError: Error loading module classes: ‘property’ object has no attribute ‘setter’

\</Console error output\>

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 25, 2016, 2:08pm UTC](https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278/2 "2016-10-25T14:08:56Z")

</div>

I don’t think the property getter/setter/deleter decorators were available in Python 2.5.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [October 25, 2016, 3:07pm UTC](https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278/3 "2016-10-25T15:07:25Z")

</div>

Those decorators are available in Jython 2.6: [docs.python.org/2/whatsnew/2.6. … ge-changes](https://docs.python.org/2/whatsnew/2.6.html#other-language-changes).

You can see the plan to upgrade Jython 2.5 to Jython 2.7 in Ignition here: [ideas.inductiveautomation.com/fo … jython-2-7](http://ideas.inductiveautomation.com/forums/255378-ignition-features-and-ideas/suggestions/7879431-upgrade-ignition-to-use-jython-2-7)

Instead of using the property decorator you can use the builtin property function. See here: [docs.python.org/2/library/funct … l#property](https://docs.python.org/2/library/functions.html#property)

Best,

---

<div class="post-metadata">

**Author:** ![thosey](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@thosey](https://forum.inductiveautomation.com/u/thosey)\
**Post date:** [October 25, 2016, 5:59pm UTC](https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278/4 "2016-10-25T17:59:15Z")

</div>

Thank you. I have decided to use this as a work around.  
So far it appears to do exactly what I am expecting it to do.

```auto
# Test Class
class Test(object):
	'Common base class for all test objects'
	# Hidden variable
	__iCount = 0
	# Instantiate the class.
	def __init__ (self):
		self.__iCount += 1
	def __del__ (self):
		print class_name, "destroyed"
		
	# Class Methods.	
	def count(self):
		return self.__iCount
	def myProp(self, value = None):
		if value is not None:
			self.__x = value
			print "setter called"
		print "Method called"
		return self.__x

```

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [September 3, 2017, 6:32am UTC](https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278/5 "2017-09-03T06:32:27Z")

</div>

I’m trying to use the property function as follows:

```auto
class State:
	def __init__ (self, value):
		print 'init'
		self._x = value
	
	def getValue(self):
		print 'get'
		return self._x
	
	def setValue(self, value):
		print 'set'
		self._x = value + 1
	
	x = property(getValue, setValue)

state = State(1)
print state.x
state.x = 5
print state.x

```

when I run the code I get the following output:

```auto
init
get
1
5

```

when I assign a value to state.x shouldn’t the setter function setValue be called? because it clearly isn’t. Otherwise the output should have some lines with:

```auto
 set

```

and the values printed should be 2 and 6. No?

I’m using 7.9.3 on JRE 1.8.0\_141

---

<div class="post-metadata">

**Author:** ![iamthebull](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@iamthebull](https://forum.inductiveautomation.com/u/iamthebull)\
**Post date:** [September 3, 2017, 8:01pm UTC](https://forum.inductiveautomation.com/t/python-property-and-settername-setter/12278/6 "2017-09-03T20:01:37Z")

</div>

Never mind… I figured out why. My class definition was not inheriting the object class.

```auto
class State(object):

```

Now it’s working fine.[quote=“thosey, post:1, topic:12278”]  
I am writing a python class and wish to use getters and setters.  
[/quote]

If you define your getters and setters this way you should be fine.
