Aug-31-2018, 07:30 AM
(This post was last modified: Aug-31-2018, 08:22 AM by Gribouillis.)
(Aug-31-2018, 06:17 AM)Skaperen Wrote: only one instance is needed when there is only one display to print to. so i really don't need a class; i can simply do this as a function.In my view of the world, there is very little benefit in using a function instead of a class. You could provide both: a function for default display and a class to make things extendable. The function would wrap a default instance. One sees this pattern now and then in some modules, for example
class NumberOutputter: """Class version for extendability""" def __init__(self, file, maxlen): self.file = file self.maxlen = maxlen def output_numbers(self, *args): ... import sys default_outputter = NumberOutputter(sys.stdout, 72) def output_numbers(*args): """function version for simple use""" return default_outputter.output_numbers(*args)