Python modules

Rick Johnson rantingrickjohnson at gmail.com
Mon Jan 14 17:27:56 CET 2013


On Monday, January 14, 2013 9:04:00 AM UTC-6, Chris Angelico wrote:
> The performance cost of reimporting a module is very low;
> in fact, trying to avoid it by adorning all your usage
> with an extra dot-level will probably cost you a lot more,
> since there'll be an extra lookup every time.

Most people "adorn" a module with an extra dot to:

    1. create a shorter name (f.e.[1] tk instead of Tkinter)
    
    2. keep their namespace clean. 

Only a fool would do "from Tkinter import *"[2]. A wise programmer, who needed to access many members of Tkinter, would do instead "import Tkinter as tk", and then prepend all members with "tk.".

[1] Abbr: (F)or (E)xample. (I feel an EnglishWart brewing on this subject!)
[2] With the exception of command line testing, learning, or playing.



More information about the Python-list mailing list