Discussion:
[Bitpim-devel] list vs tuple in bpcalendar
Stephen Wood
2004-07-22 03:36:52 UTC
Permalink
In newentryfactory in bpcalendar.py, the start and end are initialized
with:

res['start']=(year, month, day, now.tm_hour, now.tm_min)
res['end']=[year, month, day, now.tm_hour, now.tm_min]

Is there a reason why start is a list and end is a tuple? Would it hurt
anything to make start a tuple?

If any change is made to the calendar entry, the start changes to a
tuple, but if one creates a new entry without changing anything and then
tries to save it to a Sanyo phone, com_sanyo will get an exception
trying to concatenate a list and tuple.

Stephen
Roger Binns
2004-07-23 19:39:02 UTC
Permalink
Post by Stephen Wood
In newentryfactory in bpcalendar.py, the start and end are initialized
res['start']=(year, month, day, now.tm_hour, now.tm_min)
res['end']=[year, month, day, now.tm_hour, now.tm_min]
Is there a reason why start is a list and end is a tuple? Would it
hurt anything to make start a tuple?
start is a tuple. end should be one as well. lists and tuples
are somewhat interchangeable, and there are regular arguments
about them. In my view, they should be tuples because they are
fixed length.
Post by Stephen Wood
If any change is made to the calendar entry, the start changes to a
tuple, but if one creates a new entry without changing anything and
then tries to save it to a Sanyo phone, com_sanyo will get an
exception trying to concatenate a list and tuple.
You can fix your code by doing one of the following:

foo = list(bar) + [1,2,3]
foo = tuple(bar) + (1,2,3)

Roger
Stephen Wood
2004-07-24 00:37:04 UTC
Permalink
Post by Roger Binns
Post by Stephen Wood
In newentryfactory in bpcalendar.py, the start and end are initialized
res['start']=(year, month, day, now.tm_hour, now.tm_min)
res['end']=[year, month, day, now.tm_hour, now.tm_min]
Is there a reason why start is a list and end is a tuple? Would it
hurt anything to make start a tuple?
start is a tuple. end should be one as well. lists and tuples
are somewhat interchangeable, and there are regular arguments
about them. In my view, they should be tuples because they are
fixed length.
OK, I got confused on by []'s and ()'s. But that means that almost
everywhere, start and end times are lists. start is a tuple only if
nothing gets changed in a new entry.
Post by Roger Binns
Post by Stephen Wood
If any change is made to the calendar entry, the start changes to a
tuple, but if one creates a new entry without changing anything and
then tries to save it to a Sanyo phone, com_sanyo will get an
exception trying to concatenate a list and tuple.
foo = list(bar) + [1,2,3]
foo = tuple(bar) + (1,2,3)
I just put list() around a few places where my code depends on a time
being a list.

Stephen

Loading...