how to break tuple to separate variables

Shalabh Chaturvedi shalabh at cafepy.com
Tue Apr 13 09:48:52 EDT 2004


Stano Paska wrote:
> 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)
> 
> # -------------------------------

Here's a hint (section 4.7.4 of Python tutorial):
http://docs.python.org/tut/node6.html#SECTION006740000000000000000

> 
> Thanks.
> 
> Stano Paska
> 

--
Shalabh





More information about the Python-list mailing list