# Class object scope issues - Part2

**URL:** <https://forum.inductiveautomation.com/t/class-object-scope-issues-part2/12581>\
**Category:** General Discussion\
**Created:** [January 19, 2017, 8:25pm UTC](https://forum.inductiveautomation.com/t/class-object-scope-issues-part2/12581 "2017-01-19T20:25:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dberry](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@dberry](https://forum.inductiveautomation.com/u/dberry)\
**Post date:** [January 19, 2017, 8:25pm UTC](https://forum.inductiveautomation.com/t/class-object-scope-issues-part2/12581/1 "2017-01-19T20:25:07Z")

</div>

Reference post: [inductiveautomation.com/forum/v … 50&t=16600](https://inductiveautomation.com/forum/viewtopic.php?f=50&t=16600)

While I was able to create a “global” class as suggested in the previous post, I am now having some difficulty with class instances being overwritten.  
In the example below, does the instance x get overwritten with it’s initialized values (y=0) every time a call to run() is made from outside the module. For example, if I call this function from a tag value change event? and if so, how would I achieve a persistent class instance?

[code]class myclass:  
def **init** (self)  
self.y=0

x=myclass()

def run():  
z = x.y[/code]

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 20, 2017, 12:53pm UTC](https://forum.inductiveautomation.com/t/class-object-scope-issues-part2/12581/2 "2017-01-20T12:53:10Z")

</div>

‘x’ does not get overwritten by run(). You must not assign to ‘x’ anywhere else, either. Keep in mind that editing your scripts and saving will re-initialize them, overwriting ‘x’ at that point.  
As an alternative, try using ‘myPersDict={}’ at the top level of a script and then writing and accessing values within it.

---

<div class="post-metadata">

**Author:** ![dberry](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@dberry](https://forum.inductiveautomation.com/u/dberry)\
**Post date:** [January 20, 2017, 11:07pm UTC](https://forum.inductiveautomation.com/t/class-object-scope-issues-part2/12581/3 "2017-01-20T23:07:40Z")

</div>

The suggested alternative, storing values in a dictionary worked.  
Thank you again.
