WebScript
WebScript

Reputation: 67

Use functions from main file in imported file

I am trying to build some python script. I have imported (import Handler) set of functions in my main script (start.py). In start.py I call one of the imported functions to dynamically import scripts from config (dir1). I need to use 1 function (message(self, text) what is in my main script start.py in class MyScript(Protocol)) in one of imported files from config. So my directory structure is:

MainDir
  start.py (main script)
  Handler.py
  config.cfg
  dir1 (dir with plugins)
    HelloWorld.py (this needs to use function from start.py)

Can you help me, please? Thank you. EDIT: Start.py is Twisted TCP server, I need tu use some twisted functions in my plugins.

Upvotes: 0

Views: 256

Answers (1)

Nathan Davis
Nathan Davis

Reputation: 5766

Here are a couple more options:

  1. Pass the function as a parameter to the code that calls it (this might be appropriate if you need that code to call different functions is different situations).
  2. Use python's -m option to load start.py as a regular module (i.e., python -m start). Then you can import start and refer to its message function just like any other python module.

Upvotes: 1

Related Questions