newbie Q: shortcuts for long module names?

DIG dig.list at nm.ru
Wed Nov 13 04:47:56 EST 2002


Hi, Robert Oschler !

 On Tue, Nov 12, 2002 at 03:21:25AM +0000, Robert Oschler wrote:

> Let's say I import a module with a long name:
> 
> import com.long.module.name
> 
> Now every time I access a function in com.long.module.name I have to prepend
> "com.long.module.name" to the member function.  Is there generally accepted
> and safe way to "alias" the module name or bring it into the local namespace
> so I can either omit or alias the module name with something much shorter?

I have seen this a few times:

    import Tkinter
    tk=Tkinter
    root = tk.Tk()
    button = tk.Button( )
    button['text'] = "test"
    root.pack() 
    root.mainloop( )

Line "tk=Tkinter" allows you to have whatever you want as a module's name.
In your case this could be:

    import com.long.module.name
    short_one = com.long.module.name

or even

    import com.long.module.name
    m = com.long.module.name


Best regards,

-- 
DIG (Dmitri I GOULIAEV)




More information about the Python-list mailing list