[Tutor] Alphabet lookup table
Alan Gauld
learn2program at gmail.com
Fri Jan 28 20:09:58 EST 2022
On 29/01/2022 00:44, Phil wrote:
> On 28/1/22 21:00, Alan Gauld via Tutor wrote:
>> BTW A class with only one method is a code smell. It means you
>> don't really need a class, you only need a data structure and
>> a function.
>
> what you mean. Is this what you had in mind?
>
> import alphabet
>
> print(alphabet.alpha_table['P'])
>
> alphabet.py contains just the dictionary lookup table.
Yes, or you could add a single function: alphabet.print_letter(letter)
So:
from alphabet import print_letter
print_letter('P')
So the single method becomes a function in the module. You still have
information hiding and a function interface but no need for a class or
instances.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list