4

is "import" in python equivalent to "include" in c++?

Can I consider namespaces from c++ the same way I do with python module names?

2
  • I'd say similar (not equivalent). That depends on how you consider python module names, but I'm not going to restrict your freedom of thought... Commented Feb 5, 2015 at 4:40
  • 1
    No. Look at [this question] (stackoverflow.com/questions/20774877/…) Commented Feb 5, 2015 at 4:44

1 Answer 1

7

#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.

Sign up to request clarification or add additional context in comments.

Comments

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.