Re: Convert string to command..

2007-10-19 Thread Hrvoje Niksic
Hrvoje Niksic <[EMAIL PROTECTED]> writes: > If you're generating the string from Python, use cPickle instead. > Much faster: [...] t0 = time.time(); d2 = eval(s); t1 = time.time(); t1-t0 > 1.5457899570465088 t0 = time.time(); d2 = pickle.loads(s); t1 = time.time(); t1-t0 > 0.060307979583

Re: Convert string to command..

2007-10-19 Thread Bruno Desthuilliers
Peter Otten a écrit : (snip) > Before you go on with your odd caching schemes -- is the database properly > indexed? Something like > > CREATE UNIQUE INDEX mytable_id1_id2 ON mytable (id-1, id-2); > > (actual syntax may differ) might speed up the lookup operation > enough that you can do without

Re: Convert string to command..

2007-10-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Oct 18, 1:38 pm, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: >> Abandoned a écrit : >> (snip) >> >>> I'm very confused :( >>> I try to explain main problem... >>> I have a table like this: >>> id-1 | id-2 | value >>> 23 24 34 >>> 56 68 66 >>>

Re: Convert string to command..

2007-10-19 Thread Peter Otten
Abandoned wrote: > I'm very confused :( > I try to explain main problem... That's always a good first step; try to remember that when you start your next thread. > I have a table like this: > id-1 | id-2 | value > 23 24 34 > 56 68 66 > 56 98 32455 > 55 62

Re: Convert string to command..

2007-10-19 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: >> Use a different column type for cache2's column, one more appropriate >> for storing binary characters (perhaps BYTEA for Postgres). Don't >> forget to also use a bind variable, something like: >> >> cursor.execute("INSERT INTO cache2 VALUES (?)", a) >> >>

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 8:53 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Abandoned <[EMAIL PROTECTED]> writes: > > > When you load it, convert the string to dict with cPickle.loads > > > instead of with eval. > > > Yes i understand and this very very good ;) > > Good! :-) > > > psycopg2.ProgrammingError: in

Re: Convert string to command..

2007-10-18 Thread Steven D'Aprano
On Thu, 18 Oct 2007 14:05:34 -0300, Sebastian Bassi wrote: > On 10/18/07, Adam Atlas <[EMAIL PROTECTED]> wrote: >> >> Use the builtin function "eval". > > What is the difference with os.system()? Everything. eval() evaluates Python expressions like "x.append(2+3)". os.system() calls your opera

Re: Convert string to command..

2007-10-18 Thread [EMAIL PROTECTED]
On Oct 18, 1:38 pm, Bruno Desthuilliers wrote: > Abandoned a écrit : > (snip) > > > I'm very confused :( > > I try to explain main problem... > > I have a table like this: > > id-1 | id-2 | value > > 23 24 34 > > 56 68 66 > > 56 98 32455 > > 55 62 655 > > 56

Re: Convert string to command..

2007-10-18 Thread Carsten Haese
On Thu, 2007-10-18 at 19:53 +0200, Hrvoje Niksic wrote: > Don't > forget to also use a bind variable, something like: > > cursor.execute("INSERT INTO cache2 VALUES (?)", a) I second the advice, but that code won't work. The bind parameters must be a sequence, and psycopg2 (unfortunately) uses %s

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > > When you load it, convert the string to dict with cPickle.loads > > instead of with eval. > > Yes i understand and this very very good ;) Good! :-) > psycopg2.ProgrammingError: invalid byte sequence for encoding "UTF8": > 0x80 > HINT: This error can a

Re: Convert string to command..

2007-10-18 Thread Bruno Desthuilliers
Abandoned a écrit : (snip) > I'm very confused :( > I try to explain main problem... > I have a table like this: > id-1 | id-2 | value > 23 24 34 > 56 68 66 > 56 98 32455 > 55 62 655 > 56 28 123 > ( 3 millions elements) > > I select where id=5

Re: Convert string to command..

2007-10-18 Thread Bruno Desthuilliers
Richard Brodie a écrit : > "Matimus" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> I think several people have given you the correct answer, but for some >> reason you aren't getting it. Instead of saving the string >> representation of a dictionary to the database... > > Mi

Re: Convert string to command..

2007-10-18 Thread Bruno Desthuilliers
Abandoned a écrit : (snip) > import cPickle as pickle > a="{2:3,4:6,2:7}" > s=pickle.dumps(a, -1) > g=pickle.loads(s); > print g > '{2:3,4:6,2:7}' > > Thank you very much for your answer but result is a string ?? > Of course it's a string. That's what you pickled. What did you hope ? If you want

Re: Convert string to command..

2007-10-18 Thread Bruno Desthuilliers
Abandoned a écrit : > On Oct 18, 6:51 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Thu, 18 Oct 2007 08:41:30 -0700, Abandoned wrote: >>> import cPickle as pickle >>> a="{2:3,4:6,2:7}" >>> s=pickle.dumps(a, -1) >>> g=pickle.loads(s); >>> print g >>> '{2:3,4:6,2:7}' >>> Thank you ver

Re: Convert string to command..

2007-10-18 Thread Richard Brodie
"Matimus" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I think several people have given you the correct answer, but for some > reason you aren't getting it. Instead of saving the string > representation of a dictionary to the database... Mind you, if this were Jeopardy, "Store

Re: Convert string to command..

2007-10-18 Thread Sebastian Bassi
On 10/18/07, Adam Atlas <[EMAIL PROTECTED]> wrote: > > Use the builtin function "eval". What is the difference with os.system()? -- Sebastián Bassi (セバスティアン). Diplomado en Ciencia y Tecnología. Curso Biologia molecular para programadores: http://tinyurl.com/2vv8w6 GPG Fingerprint: 9470 0980 620D

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 7:40 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Abandoned <[EMAIL PROTECTED]> writes: > > Sorry i can't understand :( > > Yes my database already has data in the "{..}" format and i select > > this and i want to use it for dictionary.. > > But, do you use Python to create that data?

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > Sorry i can't understand :( > Yes my database already has data in the "{..}" format and i select > this and i want to use it for dictionary.. But, do you use Python to create that data? If so, simply convert it to pickle binary format instead of "{...}".

Re: Convert string to command..

2007-10-18 Thread Matimus
On Oct 18, 9:09 am, Abandoned <[EMAIL PROTECTED]> wrote: > On Oct 18, 6:57 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > > > > Abandoned wrote: > > > On Oct 18, 6:35 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > >> Abandoned wrote: > > >> > On Oct 18, 6:14 pm, "Diez B. Roggisch" <[E

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > I select where id=56 and 100.000 rows are selecting but this took 2 > second. (very big for my project) > I try cache to speed up this select operation.. > And create a cache table: > id-1 | all > 56{68:66, 98:32455, 62:655} If you use Python to create

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 7:02 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Abandoned <[EMAIL PROTECTED]> writes: > > import cPickle as pickle > > a="{2:3,4:6,2:7}" > > s=pickle.dumps(a, -1) > > g=pickle.loads(s); > > print g > > '{2:3,4:6,2:7}' > > > Thank you very much for your answer but result is a string ?

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > import cPickle as pickle > a="{2:3,4:6,2:7}" > s=pickle.dumps(a, -1) > g=pickle.loads(s); > print g > '{2:3,4:6,2:7}' > > Thank you very much for your answer but result is a string ?? Because you gave it a string. If you give it a dict, you'll get a dict:

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 6:57 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Abandoned wrote: > > On Oct 18, 6:35 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > >> Abandoned wrote: > >> > On Oct 18, 6:14 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > >> >> Abandoned wrote: > >> >> > Thanks you all

Re: Convert string to command..

2007-10-18 Thread Diez B. Roggisch
Abandoned wrote: > On Oct 18, 6:35 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Abandoned wrote: >> > On Oct 18, 6:14 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> >> Abandoned wrote: >> >> > Thanks you all answer.. >> >> > But "eval" is very slow at very big dictionary {2:3,4:5,6:1

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 6:51 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 18 Oct 2007 08:41:30 -0700, Abandoned wrote: > > import cPickle as pickle > > a="{2:3,4:6,2:7}" > > s=pickle.dumps(a, -1) > > g=pickle.loads(s); > > print g > > '{2:3,4:6,2:7}' > > > Thank you very much for your answe

Re: Convert string to command..

2007-10-18 Thread Marc 'BlackJack' Rintsch
On Thu, 18 Oct 2007 08:41:30 -0700, Abandoned wrote: > import cPickle as pickle > a="{2:3,4:6,2:7}" > s=pickle.dumps(a, -1) > g=pickle.loads(s); > print g > '{2:3,4:6,2:7}' > > Thank you very much for your answer but result is a string ?? In Python terms yes, strings in Python can contain any by

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 6:35 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Abandoned wrote: > > On Oct 18, 6:14 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > >> Abandoned wrote: > >> > Thanks you all answer.. > >> > But "eval" is very slow at very big dictionary {2:3,4:5,6:19} > >> > (100.000 el

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 6:26 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Abandoned <[EMAIL PROTECTED]> writes: > > 173.000 dict elements and it tooks 2.2 seconds this very big time > > for my project > > If you're generating the string from Python, use cPickle instead. > Much faster: > > >>> import time > >>

Re: Convert string to command..

2007-10-18 Thread Diez B. Roggisch
Abandoned wrote: > On Oct 18, 6:14 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Abandoned wrote: >> > Thanks you all answer.. >> > But "eval" is very slow at very big dictionary {2:3,4:5,6:19} >> > (100.000 elements) >> > Is there any easy alternative ? >> >> How big? How slow? For me,

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > 173.000 dict elements and it tooks 2.2 seconds this very big time > for my project If you're generating the string from Python, use cPickle instead. Much faster: >>> import time >>> d = dict((i, i+1) for i in xrange(17)) >>> len(d) 17 >>> s=repr(d)

Re: Convert string to command..

2007-10-18 Thread Abandoned
On Oct 18, 6:14 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Abandoned wrote: > > Thanks you all answer.. > > But "eval" is very slow at very big dictionary {2:3,4:5,6:19} > > (100.000 elements) > > Is there any easy alternative ? > > How big? How slow? For me, a 1-element list takes

Re: Convert string to command..

2007-10-18 Thread Diez B. Roggisch
Abandoned wrote: > Thanks you all answer.. > But "eval" is very slow at very big dictionary {2:3,4:5,6:19} > (100.000 elements) > Is there any easy alternative ? How big? How slow? For me, a 1-element list takes 0.04 seconds to be parsed. Which I find fast. Diez -- http://mail.python.o

Re: Convert string to command..

2007-10-18 Thread Abandoned
Thanks you all answer.. But "eval" is very slow at very big dictionary {2:3,4:5,6:19} (100.000 elements) Is there any easy alternative ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert string to command..

2007-10-18 Thread Diez B. Roggisch
Abandoned wrote: > I want to convert a string to command.. > For example i have a string: > a="['1']" > I want to do this list.. > How can i do ? The correct wording here would be expression. To evaluate expressions, there is the function eval: a = eval("['1']") But beware: if the expression co

Re: Convert string to command..

2007-10-18 Thread Adam Atlas
On Oct 18, 10:23 am, Abandoned <[EMAIL PROTECTED]> wrote: > I want to convert a string to command.. > For example i have a string: > a="['1']" > I want to do this list.. > How can i do ? Use the builtin function "eval". -- http://mail.python.org/mailman/listinfo/python-list