1

There's an excellent answer for the same question for Python 2: Importing module from string in the Python C API

I tried that in Python3 but it seems that this doesn't work anymore. The code compiles but when I try to do print(blah) I get:

Traceback (most recent call last):
  File "<string>", line 9, in <module>
NameError: name 'blah' is not defined

Does anyone know what could have changed?

  • This is far from perfect but I've found a method to make this work: I imported dict created this way into builtins: `PyDict_SetItemString(builtins, "dict", dict);` and then transformed it into namespace using `argparse.Namespace`. – John Liewelson Jun 30 '20 at 15:15

0 Answers0