Skip to main content
Solved

Re-use python script in multiple workspaces


Forum|alt.badge.img

Hi,

I am trying to re-use a python script (saved as .py file), so that i do not have to edit all my workspaces that contain this script in a private parameter.

I tried to follow the steps in

 https://knowledge.safe.com/articles/976/how-can-i-modularize-my-python-code.html

whereby I included a couple of codes within the python startup script something like below:

when I try referring the SetReader module in a private parameter, I get an error that says 'ImportError: No module named SetReader'

Can I please get some help regarding re-using python scripts ?

Thanks very much

import sys sys.path.append(r'\\fmeserver\Functions'import SetReader

Best answer by david_r

Have a look here: http://stackoverflow.com/questions/4383571/importing-files-from-different-folder-in-python

The most important thing is that the entry you add to the Python path needs to be absolute.

You might also want to familiarize yourself with the __init__.py convention: http://stackoverflow.com/questions/448271/what-is-init-py-for

View original
Did this help you find an answer to your question?

2 replies

david_r
Evangelist
  • Best Answer
  • November 21, 2016

Have a look here: http://stackoverflow.com/questions/4383571/importing-files-from-different-folder-in-python

The most important thing is that the entry you add to the Python path needs to be absolute.

You might also want to familiarize yourself with the __init__.py convention: http://stackoverflow.com/questions/448271/what-is-init-py-for


Forum|alt.badge.img
  • Author
  • November 21, 2016
david_r wrote:

Have a look here: http://stackoverflow.com/questions/4383571/importing-files-from-different-folder-in-python

The most important thing is that the entry you add to the Python path needs to be absolute.

You might also want to familiarize yourself with the __init__.py convention: http://stackoverflow.com/questions/448271/what-is-init-py-for

Thanks. The 1st link was of good help !

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings