I got it! How to force a single number to be a tuple

Colin J. Williams cjw at sympatico.ca
Wed Aug 4 21:51:27 CEST 2004



Jinming Xu wrote:
> Sorry for the previous message. It's really a simple question and I have 
> solved it myself.
> 
> Thanks,
> 
> Jinming
> 
> ------------------------------------------------------------------------
> Hi Folks,
> 
> I have a number sequence, which is put into a tuple like this:
> 
> y=2, 3.0, 4.5
> 
> I can manipulate the sequence as a tuple when it has more than 1 number. 
> But when the sequence has only 1 number, like
> 
> y=2
> 
> I have trouble to manipulate it as a tuple.  I guess there must be a way 
> to forece a single number to be a tuple. Could anyone please tell me that?
> 
> Thanks,
> 
> Jinming
> 
> _________________________________________________________________
> Discover the best of the best at MSN Luxury Living. http://lexus.msn.com/
> 
Maybe something like:
[Dbg]>>> y= 6
[Dbg]>>> if not isinstance(x, (tp.ListType, tp.TupleType)):
[Dbg]... 	y= (y, )
[Dbg]... 	
[Dbg]>>> print y
(6,)
[Dbg]>>>
Colin W.




More information about the Python-list mailing list