Is there a better algorithm?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Jan 5 21:58:58 EST 2009
En Sat, 03 Jan 2009 02:55:12 -0200, Kottiyath <n.kottiyath at gmail.com>
escribió:
>> tuples = [(1, 2), (3, 4, 5), (6, 7)]
>
> It is a code to post some data to HTML server.
> Even though usually the POST values are of type(name, value), if file
> transfer is involved, then POST values change to (name, filename,
> value).
> My view was that since filename is a rare occurance and doesnt make
> sense in a usual POST, I had not kept it as a full 3 tuple.
> Since so many programmers (that too much more capable than me) are
> suggesting that it is code smell, I am reviewing my decision.
What about using another data structure instead - like this:
class entry:
filename = None
def __init__(self, name, value, filename=None):
self.name = name
self.value = value
if filename is not None:
self.filename = filename
[entry('name', 'Gabriel'), entry('age', 18), entry('pic', picture_data,
'path/to/file')]
--
Gabriel Genellina
More information about the Python-list
mailing list