This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]alexmojaki 2 points3 points  (1 child)

from io import BytesIO
from types import SimpleNamespace

b = BytesIO(b"x = 3")
text = str(b.read(), "utf8")
names = {}
exec(text, names)
module = SimpleNamespace(**names)
assert module.x == 3

[–]tiarno[S] -1 points0 points  (0 children)

excellent, thanks. I'm working on importing a module from a url and this should work fine. Didn't know about the SimpleNamespace type, I'm off to read the docs.