Hi Maik.
I don't know if this is the "correct" solution, but this code in myScript.py will put those class definitions (well, any global definitions in classDefinitions.py) into myScript.py's global namespace:

from os.path import join, dirname
with open(join(dirname(__file__), "classDefinitions.py")) as f:
        exec(f.read(), globals(), locals())

--Eric

Eric Pettersen
UCSF Computer Graphics Lab

On Apr 17, 2024, at 2:03 PM, Engeholm, Maik via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:

Hi there,

I'm running a python script either from within ChimeraX (with "open myScript.py") or from the command line (using "chimerax myScript.py"). As the script gets longer and longer, I would like to store some class definitions in a separate file (classDefinitions.py within the same directory as myScript.py) and then import those into the main script with some command like "from classDefinitions import testClass". This, however, gives me an "ModuleNotFoundError: No module named 'testClass'". What is the correct way to do this?

Any help would be much appreciated!

Cheers,

Maik 

_______________________________________________
ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu
To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu
Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/