Skip to main content
Solved

Re-use python script in multiple workspaces

  • November 21, 2016
  • 2 replies
  • 12 views

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

david_r
Celebrity
  • 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

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 !