Lets say I have the code:
class NoneDict(dict):
def __getitem__(self, name):
try:
return super(NoneDict, self).__getitem__(name)
except:
return None
I want people to be able to create a NoneDict object without writing all this code out. I tried including it in a module and then typed:
import nonedict
foo = NoneDict()
But it didn't work. How can I make it so someone can import the module and then be able to create a nonedict without typing out all the code?
import nonedict
foo = nonedict.NoneDict()
or
from nonedict import NoneDict
foo = NoneDict()
or (thanks @Joel Cornett)
from nonedict import NoneDict as nd
foo = nd()
from nonedict import NoneDict as nd
Joel Cornett 2012-04-05 03:39
from nonedict import NoneDict
- Praveen Gollakota 2012-04-05 02:44