How to import a function from another module...

Steven D'Aprano steve at
Tue Aug 4 03:24:23 CEST 2015

On Tue, 4 Aug 2015 09:57 am, Dwight GoldWinde wrote:

> I am trying to import a function defined in another module.

You can't use spaces in the name of importable Python modules: change the
name from "Simulate" to "". You can use spaces
in file names if they are only used as a runnable script and not imported.

Then use this:

from simulate_python import humprint

There's no need to use importlib.

You may need to arrange for the simulate_python file to be placed somewhere
in the Python search path. Do you need help with that?

What you are trying to do with importlib is fight the language. Your life
will be much simpler if you work within the parameters of how the language
is designed to work.


More information about the Python-list mailing list