# Dynamically call different python functions from shared libr

**URL:** <https://forum.inductiveautomation.com/t/dynamically-call-different-python-functions-from-shared-libr/10689>\
**Category:** Ignition\
**Created:** [October 28, 2015, 5:13pm UTC](https://forum.inductiveautomation.com/t/dynamically-call-different-python-functions-from-shared-libr/10689 "2015-10-28T17:13:48Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [October 28, 2015, 5:13pm UTC](https://forum.inductiveautomation.com/t/dynamically-call-different-python-functions-from-shared-libr/10689/1 "2015-10-28T17:13:48Z")

</div>

Is there a way to accomplish the following?

I want to pass a string variable functionName to a tag event script and call a function from the shared script library of the same name.

ie. if functionName = “myFunction1” then call shared.myScripts.myFunction1()

I don’t want to use a lookup table or an if statement because my list of functions to choose from will be lengthy.

I know I can pass functions as an object. Is is possible for me to get the function from the script module as an object with the string variable functionName?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 28, 2015, 9:05pm UTC](https://forum.inductiveautomation.com/t/dynamically-call-different-python-functions-from-shared-libr/10689/2 "2015-10-28T21:05:07Z")

</div>

Sure!

`x= getattr(shared.myScripts,'myFunction1')()
print x`

---

<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:** [October 28, 2015, 9:05pm UTC](https://forum.inductiveautomation.com/t/dynamically-call-different-python-functions-from-shared-libr/10689/3 "2015-10-28T21:05:49Z")

</div>

Use jython’s [eval()](http://www.jython.org/docs/library/functions.html) function to convert the function name (in a custom property?) to a function object, then call it with a common set of parameters. You probably want to pass at least the event object.

`func = eval('shared.myScripts.'+event.source.functionName)
func(event)`

---

<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:** [October 29, 2015, 5:34am UTC](https://forum.inductiveautomation.com/t/dynamically-call-different-python-functions-from-shared-libr/10689/4 "2015-10-29T05:34:46Z")

</div>

Sweet! That was easy!

Thanks guys!
