[Zope] string to list

Bo M. Maryniuck b.maryniuk@forbis.lt
Wed, 18 Sep 2002 10:29:47 +0200


On Tuesday 17 September 2002 17:50, DA Loeffler wrote:
> Try the Python eval() function:
> >>> eval('["foo","bar"]')
>
> ['foo', 'bar']
Using eval() in this case is lame and unsafe:
>>> eval('[__import__("os").system("touch /tmp/foo;ls -l /tmp/foo;echo \'=
Th15 b0x 15 0wn3D\'")]')
-rw-r--r--    1 bo       users           0 Sep 18 10:18 /tmp/foo
Th15 b0x 15 0wn3D
[0]


> > Does anyone have
> > a conventient way to turn the string back into a list or should I jus=
t do
> > the store differently?
Sure! Why you need to save list as string? You can store as:
 - string with some special separator, e.g.:

=09import random
=09self.separator =3D '_%s_' % random.randint(0xfff, 0xfffff)

=09...

=09addThisToDB =3D self.separator.join(yourList)

   Then:

=09for item in gotBigStringFromDB.split(self.separator):=20
=09=09self.doSomethingWith(item)

 - Make a one more relative table and have less traffic.

--=20
Regards, Bogdan

Your eyes are weary from staring at the CRT.  You feel sleepy.  Notice ho=
w
restful it is to watch the cursor blink.  Close your eyes.  The opinions
stated above are yours.  You cannot imagine why you ever felt otherwise.