# Python Decorator Help - Accessing variables within the decorator from within the decorating function

**URL:** <https://forum.inductiveautomation.com/t/python-decorator-help-accessing-variables-within-the-decorator-from-within-the-decorating-function/85347>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [February 7, 2024, 5:15am UTC](https://forum.inductiveautomation.com/t/python-decorator-help-accessing-variables-within-the-decorator-from-within-the-decorating-function/85347 "2024-02-07T05:15:02Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 7, 2024, 2:00pm UTC](https://forum.inductiveautomation.com/t/python-decorator-help-accessing-variables-within-the-decorator-from-within-the-decorating-function/85347/8 "2024-02-07T14:00:14Z")

</div>

An alternative way to do decorators with a class and functools here, I find it a little bit easier to work with but in reality anytimes I touch decorators I need a small referesher lol- [Script Benchmarking with Decorators Example - #4 by dkhayes117](https://forum.inductiveautomation.com/t/script-benchmarking-with-decorators-example/63507/4)

If you note the first answer in the link @dkhayes117 returns the function result if there is one or None if there is an error and you can use your control flow like that.

I modified that a bit, I always return a Response object which is just

```auto
class Response:
    success: bool - true if no errors, false otherwise
    result: Any, whatever the result of the function was, None if success was False
    errorType: str - python or java to indicate what type of error
    errorMsg: the relevant error message (depends on if python or java)

```

So I decorate my most basic Business Logic with this, and then I can do control flow from that - was it successful - do X, was it a python error - I probably messed up code and need to tell them to alert me, if it's java, it may just be a expected database error and I can show a useful error to the end user etc. Seems like this may sort of be what you are trying to do, not sure your end goal though. Hope this is helpful.

---

_[View the full topic](https://forum.inductiveautomation.com/t/python-decorator-help-accessing-variables-within-the-decorator-from-within-the-decorating-function/85347)._
