G
Gordon Airporte
I'm wondering if this is might be bad practice. Sometimes when I need to
pass around several pieces of datum I will put them in a tuple, then
when I need to use them in a receiving function I get them out with
subscripts. The problem is that the subscript number is completely
meaningless and I have to remember the order I used.
As an alternative I was considering using a dummy class like this:
class Dummy:
pass
Then when I need to pass some related data, Python lets me do this:
prefill = Dummy()
prefill.foreground = 'blue' #"foreground" is made up on the fly
prefill.background = 'red'
prefill.pattern = mypattern
return prefill
Now I can access the data later using meaningful names.
Is this going to cause problems somehow? Should I rather go to the
trouble of creating more substantial individual classes for every
grouping of data I might need to pass (with __init__'s and default
values and so on)? Should I just stick with subscripted groupings
because of the overhead?
pass around several pieces of datum I will put them in a tuple, then
when I need to use them in a receiving function I get them out with
subscripts. The problem is that the subscript number is completely
meaningless and I have to remember the order I used.
As an alternative I was considering using a dummy class like this:
class Dummy:
pass
Then when I need to pass some related data, Python lets me do this:
prefill = Dummy()
prefill.foreground = 'blue' #"foreground" is made up on the fly
prefill.background = 'red'
prefill.pattern = mypattern
return prefill
Now I can access the data later using meaningful names.
Is this going to cause problems somehow? Should I rather go to the
trouble of creating more substantial individual classes for every
grouping of data I might need to pass (with __init__'s and default
values and so on)? Should I just stick with subscripted groupings
because of the overhead?