[Tutor] Re: small problem with lists/tuples [evil test cases]

pan at uchicago.edu pan at uchicago.edu
Mon Sep 29 16:54:43 EDT 2003


> > The following simple trick might work:
> >
> > >>> a = ([['data']])
> > >>> a
> > [['data']]
> >
> > >>> def unpack(target):
> > .. 	tmp = str(target)
> > .. 	tmp = tmp.replace('[','').replace(']','')
> > .. 	tmp = tmp.replace('(','').replace(')','')
> > .. 	return eval(tmp)
> > ..
> 
> Hi Pan,
> 
> Unfortunately, the implementation above is a little unsafe.  

Ya, you are right. My example only works when you are sure what
is in the data. That's why I said **might** work. :) 

pan



More information about the Tutor mailing list