Good style for multi-valued returns
Rob W. W. Hooft
rob at hooft.net
Tue Apr 25 06:23:53 EDT 2000
>>>>> "CL" == Cameron Laird <claird at starbase.neosoft.com> writes:
CL> Let me guess: folks generally pass tuples for small and
CL> determinate-in-number multi-values, and dictionaries other- wise,
CL> 'cept some do it all with tuples. Accurate?
I sometimes use:
class Record:
"""Empty class for misc use"""
_format={}
def __init__(self,**kw):
for key,value in kw.items():
setattr(self,key,value)
def __repr__(self):
t=[]
for i in dir(self):
if i[0]!="_":
if self._format.has_key(i):
if self._format[i]:
t.append("%s=%s"%(i,self._format[i]%getattr(self,i)))
else:
t.append("%s=%s"%(i,repr(getattr(self,i))))
import string
return "Record: "+string.join(t)
def copy(self):
import copy
return copy.copy(self)
--
===== rob at hooft.net http://www.xs4all.nl/~hooft/rob/ =====
===== R&D, Nonius BV, Delft http://www.nonius.nl/ =====
===== PGPid 0xFA19277D ========================== Use Linux! =========
More information about the Python-list
mailing list