So I am trying to import a method into a script from another file. It works, except when I refer to the magic Glyphs
global. Running the script directly (and in it calling the method) works. Importing the method to another script fails.
With both files at the root of a folder in scripts
:
test_module.py
:
#MenuTitle: Test module
print(Glyphs.font)
def foo():
print("foo()")
foo()
test_import.py
:
#MenuTitle: Test importing
import test_module
print(Glyphs.font)
print(test_module.foo())
Running Test module
(without active font):
Start
None
foo()
End
Running Test import
(without active font):
Start
Traceback (most recent call last):
File “test_import.py”, line 2, in
import test_module
File “test_module.py”, line 3, in
print(Glyphs.font)
NameError: name ‘Glyphs’ is not defined
End
Am I missing something stupid here? Should this work or is this expected to fail?
Cheers,
Johannes