namespaces
Paolino
paolo_veronelli at tiscali.it
Sun Jul 31 09:09:48 EDT 2005
Steven D'Aprano wrote:
> def translate(text):
> import string
> all=string.maketrans('','')
> badcars=all.translate(all,string.letters+string.digits)
> table=string.maketrans(badcars,'_'*len(badcars))
> return text.translate(table)
>
> No pollution.
And no efficience.Recalculating all,badcars and table was not an
acceptable solution ,sorry if I didn't state this point :(
> Then after you are finished with the bindings, delete them:
>
> import string
> all=string.maketrans('','')
> badcars=all.translate(all,string.letters+string.digits)
> table=string.maketrans(badcars,'_'*len(badcars))
> def translate(text):
> return text.translate(table)
> # clean up the temporary variables so as to prevent namespace pollution
> del string; del all; del badcars; del table
Well,a solution but not a programming pattern for an elegant language ?
More this is also loosing informations.
Probably I've not been clear with the word pollution and the example is
poor.
I didn't mean 'binding to unuseful informations' but 'bindings in a non
-structured organization'
I restate the problem.Python is in some ways unable to project the
module structure inside the module.Or ... namespace pattern instances
seems not deriving from a common pattern.
Finally, (before I get polemic which is not my aim) I start thinking
classes (namespaces defined via 'class' keyword) are a specialization of
generic namespaces in which there-defined methods get a special way of
being called and __call__ method is a way of cloning access to them.
(Thin ice....)
Don't really know if modules can be defined as specialization of
generic namespaces and be placed somewhere next to classes.
Even worse I get with methods and function namespaces.
Rob Williscroft wrote:
> After 3 or 4 iterations I refactored you code to this:
>
> def translate( text )
> import string
> all=string.maketrans('','')
> badcars=all.translate(all,string.letters+string.digits)
> TABLE = string.maketrans(badcars,'_'*len(badcars))
>
> global translate
> def translate( text ):
> return text.translate(TABLE)
>
> return translate( text )
There is a way to access 'all' and 'badcars' here?
In my trial translate.all and translate.badcars can be accessed easily
and maybe coherently.
Thanks a lot, and don't tell me 'the dictator has marked the trail' ;)
___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
More information about the Python-list
mailing list