namespaces

P

Paolino

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,775
Messages
2,569,601
Members
45,182
Latest member
alexanderrm

Latest Threads

Top