how to break tuple to separate variables
Peter Abel
PeterAbel at gmx.net
Tue Apr 13 12:12:05 EDT 2004
Stano Paska <Stanislav.Paska at kios.sk> wrote in message news:<mailman.572.1081846104.20120.python-list at python.org>...
> Hi.
>
> I need pass variables to function like tuple, but function accepts
> separate variables.
>
> Is there some elegant solution?
>
> My example:
>
> # -------------------------------
> import datetime
>
> def date2tuple(aaa):
> try:
> y = int(aaa[:4])
> m = int(aaa[5:7])
> d = int(aaa[8:10])
> except:
> y = m = d = 0
> return (y, m, d)
>
> # i need some like this
> bbb = datetime.date(date2tuple('2004-11-03'))
>
> # but date requires
> bbb = datetime.date(2004, 11, 03)
>
> # -------------------------------
>
> Thanks.
>
> Stano Paska
Sorry, I didn't read your post seriously enough.
>> map(int,'2004-11-03'.split('-'))
[2004, 11, 3]
bbb = datetime.date(*map(int,'2004-11-03'.split('-')))
as Paul Rubin pointed out.
Regards
Peter
More information about the Python-list
mailing list