Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you alias a python class to have another name without using inheritance?

Tags:

python

If I have a python class, how can I alias that class-name into another class-name and retain all it's methods and class members and instance members? Is this possible without using inheritance?

e.g. I have a class like:

class MyReallyBigClassNameWhichIHateToType:     def __init__(self):          <blah>     [...] 

I'm creating an interactive console session where I don't want my users' fingers to fall off while instantiating the class in the interactive sessions, so I want to alias that really long class name to something tiny like 'C'. Is there an easy way to do this without inheritance?

like image 984
Ross Rogers Avatar asked May 08 '09 17:05

Ross Rogers


People also ask

What is alias name in Python?

In Python, aliasing happens whenever one variable's value is assigned to another variable, because variables are just names that store references to values.

What is __ init __ in Python?

The __init__ method is the Python equivalent of the C++ constructor in an object-oriented approach. The __init__ function is called every time an object is created from a class. The __init__ method lets the class initialize the object's attributes and serves no other purpose. It is only used within classes.

How do you instantiate a class in Python?

Instantiating a class in Python is simple. To instantiate a class, we simply call the class as if it were a function, passing the arguments that the __init__ method defines. The return value will be the newly created object.


1 Answers

C = MyReallyBigClassNameWhichIHateToType 
like image 105
SilentGhost Avatar answered Oct 07 '22 18:10

SilentGhost