aliasing a package name

11 次查看(过去 30 天)
A.B.
A.B. 2023-12-15
评论: A.B. 2023-12-15
Suppose I have a package named Donaudampfschiffahrtselektrizitatenhauptbetriebswerkbauunter and I want to import it with a short name like don. In Python, I'd do import Donaudampfschiffahrtselektrizitatenhauptbetriebswerkbauunter as don. Is there an equivalent in MATLAB?

回答(1 个)

Pratyush
Pratyush 2023-12-15
编辑:Pratyush 2023-12-15
Hi A.B.,
I understand that you have a package with a very lengthy name, and you'd like to use elements from that package without having to type out the full name repeatedly.
In MATLAB, you cannot directly assign an alias to a package when importing it, as you would in Python. Instead, you can utilize the 'import' function to bring specific functions or classes from a package into the current namespace. This can help reduce the amount of typing required to use them, but it does not allow you to rename the package itself. You can refer to the following documentation for more details: https://in.mathworks.com/help/matlab/ref/import.html
If you really need to use a shorter name for convenience, and you're dealing with a class, you could create a simple wrapper function or class with a shorter name that calls the original from the long-named package. For example:
function result = don(varargin)
result = Donaudampfschiffahrtselektrizitatenhauptbetriebswerkbauunter.someFunction(varargin{:});
end
By doing this, you can call don instead of using the full package name. However, you would need to create such a wrapper for each function or class you intend to use.
  1 个评论
A.B.
A.B. 2023-12-15
Thank you for your answer and help. It's a bummer that MATLAB does not have such a capability.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by