[Tutor] automatically add it to all the classes
Alan Gauld
alan.gauld at btinternet.com
Mon Oct 30 09:18:59 CET 2006
"anil maran" <anilmrn at yahoo.com> wrote
> All the classes in my webpy application have the following lines
> is there anyway to automatically add it to all the classes in
> code.py,
> user.py
Without more information about your application we can't give
a definitive answer.
But if they inherit from a common ancestor you could put the
code there.
Alternativelyyou could create a mixin class that all other
classes inherit using multiple inheritance.
Alternatively you could create a function and call that from
all classes.
Alternatively you could create a new class that does what
you want and create an instance in the constructor of each
of the other classes.
Alternatively you could create a global variable and store
everything there, maybe using a dictionary or list if necessary.
There are other possibilities too but we really don't know
enough about what you are trying to do to be able to say
anything more specific..
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
> If it is too basic, please pardon my naivette.
> thanks
> John
> These are the lines shared by all classes,
> @checkaccess(auth=True)
>
> sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()
>
> in a class
> class index:
> @checkaccess(auth=True)
> def GET(self):
> sess = web.ctx.environ['com.saddi.service.session'].session
> meta_desc = 'myMetaData'
> title = 'title'
> session=web.cookies()
>
>
> Anil
>
> ---------------------------------
> We have the perfect Group for you. Check out the handy changes to
> Yahoo! Groups.
--------------------------------------------------------------------------------
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list