在C ++中包含vs在python中导入 [英] include in C++ vs import in python

查看:49
本文介绍了在C ++中包含vs在python中导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python中的"import"是否等效于c ++中的"include"?

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

我可以像使用python模块名称一样使用c ++来考虑名称空间吗?

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

推荐答案

#include 在C和C ++中是文本包含.Python中的 import 非常与众不同-完全没有文本包含!

#include in C and C++ is a textual include. import in Python is very different -- no textual inclusion at all!

相反,Python的 import 允许您访问由独立实现的模块导出的名称.C或C ++中的某些 #include 可能起类似的作用-提供从其他地方访问可公开访问的名称的权限-但它们也可能会做很多不同的事情 other ,你不容易说出来.

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.

例如, .cc 源文件对相应的 .h 头文件进行 #include 正常是很正常的,以确保它准确地实现了该头文件可在其他地方使用-在Python(或Java或AFAIK以及其他大多数现代语言)中没有此头文件.

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 也可能与使可用有关……并且Python非常有意地选择不包含宏,因此,不存在任何等同之处!-)

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

这篇关于在C ++中包含vs在python中导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆