Reputation: 399
I know we can import modules and just embed Python code in C++ and evaluate it. But how can I use built-in functions like print
or open
? These functions off course aren't module. Evaluating embedded open
statement just gives me the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'open' is not defined
Stuck. Please help me.
Upvotes: 1
Views: 434
Reputation: 3419
Try importing the builtins
and io
module and if you want any other function just call the __module__
attribute to find about which module to import
>>> print.__module__
'builtins'
>>> open.__module__
'io'
Upvotes: 1