is "import" in python equivalent to "include" in c++?
Can I consider namespaces from c++ the same way I do with python module names?
#include in C and C++ is a textual include. import in Python is very different -- no textual inclusion at all!
Rather, Python's import lets you access names exported by a self-contained, separately implemented module. Some #includes in C or C++ may serve similar roles -- provide access to publicly accessible names from elsewhere -- but they could also be doing so many other very different things, you can't easily tell.
For example it's normal for a .cc source file to #include the corresponding .h header file to make sure it's implementing precisely what that header file makes available elsewhere -- there's no equivalent of that in Python (or Java or AFAIK most ohter modern languages).
#include could also be about making macros available... and Python very deliberately chooses to have no macros, so, no equivalence!-)
All in all, I think the analogy is likely to be more confusing than helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With