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?

1
  • 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. Commented Jun 30, 2020 at 15:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.