tags:

views:

616

answers:

4

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?

A: 

Refactor the name, no reason it should have a name that long.

Otherwise whateverName = VeryLongClassName should do the trick.

Yuval A
The name isn't that long, but I want it to be exactly 1 character when I use the class in the interactive session.
Ross Rogers
+15  A: 
C = MyReallyBigClassNameWhichIHateToType
SilentGhost
Works well, but leads to confusion on the long run. If you hate to type it, why not just fix the name once and forever?
S.Lott
I was exaggerating. The original name is 7 characters long, but I truly want the interactive name to be 1 character long.
Ross Rogers
+7  A: 

You can simply do:

ShortName = MyReallyBigClassNameWhichIHateToType

A class in Python is just an object like any other, and can have more than one names.

dF
+6  A: 

Also, if you're importing the name from another module...

from modulename import ReallyLongNameWhichIHateToType as FriendlyName
James Emerton
You beat me to it!
Jason Baker