Q:

Python - How to allow the use of a function in different modules?

I have 2 scripts.
Main.py
Update.py

I have a function in Main.py which basically does the following:
def log(message):
   print(message)
   os.system("echo " + message + " >> /logfile.txt")

And in the Update.py file I have a single function which basically does the update. However throughout the update function, it calls "log(message)" with whatever the message is at that point.
The problem now though is I'm getting a NameError: global name "log" is not defined whenever I try use the function outside of the Main.py script. 
Any help? on how I would be able to use the function 'log' wherever? 
*Code simplified for explanation.
EDIT:
Main.py imports Update from /Scripts/Update.py
Update.py imports log from Main.py

When i try this, it fails saying "cannot import name Update"

A:

Don't import log from Main. That'll rerun the code in Main.py, since running Main.py as a script and importing it as a module aren't equivalent. Other modules should not depend on functions defined in the main script. Instead, put your log function in another module and import that, or have Main.py explicitly pass a logger to the other modules somehow.
Update: You can't import Update because Python can't find it. Python checks in 4 places for modules to import, but the ones you should be interested in are

the directory the script was from, and
the directories specified in the PYTHONPATH environment variable.

You'll either need to put Main.py and the things it imports in the same directory, or add /Scripts to your PYTHONPATH.

