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
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
[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
>>>
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
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)
>>
>>
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
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
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
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
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
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
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
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
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
"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
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
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?
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 "{...}".
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
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
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 ?
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:
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
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
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
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
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
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
> >>
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,
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)
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
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
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
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
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
35 matches
Mail list logo