Jun-21-2017, 10:00 PM
To use the class you have to create an instance so you code should have something like:
looking it up:
alphabet=Alphabet() alphabet['k'] # will call alphabet.__getitem__('k')Note that nothing says how you initialize the mapping with data, that's up to you. And __getitem__ can just as well compute the answer instead of
looking it up:
import collections class Alphabet(collections.Mapping): def __len__(self): pass def __iter__(self): pass def __getitem__(self,key): return ord((key.lower()[0]))-96 alphabet=Alphabet() print (alphabet['a']) print (alphabet['A']) print (alphabet['z'])Btw, using
numpy
just to read a file is gross.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net