On Feb 4, 2006, at 5:01 PM, Patrick Lewis wrote:


Hi gasolin,

There is no real reason to maintain the module declaration if you can
be assured that no other variable or function will overwrite expose.
In your sample, there isn't a problem.  But, cherrypy has an expose
method, so if you did:

from turbogears import expose, controllers
from cherrypy import *

class Root(controllers.RootController):
    @expose()
    def index(self):
        return "Hello World!"

You would be using cherrypy.expose, rather than turbogears.expose.

Generally speaking it's probably best not to use import * unless you
are sure of what that will bring in to your namespace.

And hey, if you are just going for sheer brevity:

from turbogears import expose as e, controllers as c
class R(c.RootController):
    @e()
    def index(s):
        return "Hello World!"

Now I've thrown down the gauntlet, and someone will be sure to
implement this in two lines. :-)


I can't quite fit it in two lines, but try:

from turbogears import expose as e, controllers as c
class R(c.RootController):
        index = e()(lamda s: "Hello world!")

to push a step further the limits of legibility... ;)

Now seriously...

import * not considered "best-parctice" fo the reasons Patrick "exposed" (see also http://www.python.org/peps/pep-0008.html), besides that, its easier (IMHO) for someone reading the code to see fully quallified names as they can spot easily where each symbol is coming from.

Alberto.

Reply via email to