namespaces

Paolino paolo_veronelli at tiscali.it
Sun Jul 31 05:14:56 EDT 2005


While it's not so bad we can bind names in the module namespace, (ex 
writing  scripts ?) ,writing modules is someway bound to not polluting 
that namespace (really IMO).

For non-functions we can use 'class' :

class ns:
   foo='something'

but writing a function there triggers the binding to 'self' behaviour.

The straight solution is @staticmethod

class ns:
   @staticmethod
   def gulp(*args):
     pass

Another solution is via metaclass

class namespaceMeta(type):
   def __init__(cls,*more):
     ## wrap all methods with staticmethod()
class namespace:
   __metaclass__=namespaceMeta

class ns(namespace):
   def gulp(*args):pass

This solution makes me think the keyword 'namespace' is missing:

namespace ns:
   foo='something'
   def gulp(*args):
     pass

Solutions and comments appreciated.

Regards Paolino

		
___________________________________ 
Yahoo! Messenger: chiamate gratuite in tutto il mondo 
http://it.beta.messenger.yahoo.com



More information about the Python-list mailing list