aliasing a package name

5 views (last 30 days)
A.B.
A.B. on 15 Dec 2023
Commented: A.B. on 15 Dec 2023
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?

Answers (1)

Pratyush
Pratyush on 15 Dec 2023
Edited: Pratyush on 15 Dec 2023
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 Comment
A.B.
A.B. on 15 Dec 2023
Thank you for your answer and help. It's a bummer that MATLAB does not have such a capability.

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!