Thursday, March 25, 2010

comp.lang.python - 6 new messages in 4 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Super() function - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/544f50a791a9c400?hl=en
* Advice Criticism on Python App - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/cb60e2410504636e?hl=en
* Is there any library for indexing binary data? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/73b172b8c5c572ff?hl=en
* sum for sequences? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/139c0887a359405b?hl=en

==============================================================================
TOPIC: Super() function
http://groups.google.com/group/comp.lang.python/t/544f50a791a9c400?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 24 2010 9:00 pm
From: "Gabriel Genellina"


En Thu, 25 Mar 2010 00:17:52 -0300, Alan Harris-Reid
<aharrisreid@googlemail.com> escribió:

> Using Python 3.1, I sometimes use the super() function to call the
> equivalent method from a parent class, for example
>
> def mymethod(self):
> super().mymethod()
> some more code...
>
> Is there any way of writing the code so that the super() call is generic
> and automatically recognises the name of the current method (ie.
> something like super().thismethod()) or do I always have to repeat the
> method name after super()?

This recipe does what you want:
http://code.activestate.com/recipes/286195-selfsuper/
(but requires a bit of black magic...)

--
Gabriel Genellina


==============================================================================
TOPIC: Advice Criticism on Python App
http://groups.google.com/group/comp.lang.python/t/cb60e2410504636e?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Mar 24 2010 9:14 pm
From: Tim Roberts


Jimbo <nilly16@yahoo.com> wrote:
>
>class stock:
> code = ""
> purchasePrice = 0
> purchaseQuantity = 0
> price = [] # list of recent prices
> recentBid = [] # list of recent bids for stock
> recentOffer = [] # list of recent offers for stock
> stockVol = [] # list of stock quantity available on
>market

Using lists as class variables is a very good way to create very surprising
bugs. Consider the following:

C:\Dev>type x.py

class test:
check = []
def __init__(self):
self.check.append(1)

x = test()
y = test()
z = test()
print x.check
print y.check
print z.check

C:\Dev>x.py
[1, 1, 1]
[1, 1, 1]
[1, 1, 1]

C:\Dev>

> def __init__(self):
> """ Default Constructor """
> self.code = ""
> self.purchasePrice = 0
> self.purchaseQuantity = 0
>
> def constructor(self, stockCode, purPrice, purQuant):
> """ Constructor """
> self.code = stockCode
> self.purchasePrice = purPrice
> self.purchaseQuantity = purQuant

The "constructor" concept here is not very Pythonic. Why not replace those
both with:

def __init__(self, stockCode="", purPrice=0, purQuant=0):
self.code = stockCode
self.purchasePrice = purPrice
self.purchaseQuantity = purQuant
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


== 2 of 2 ==
Date: Wed, Mar 24 2010 10:10 pm
From: Steven D'Aprano


On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote:

> Jimbo <nilly16@yahoo.com> wrote:
>>
>>class stock:
>> code = ""
>> purchasePrice = 0
>> purchaseQuantity = 0
>> price = [] # list of recent prices
>> recentBid = [] # list of recent bids for stock
>> recentOffer = [] # list of recent offers for stock
>> stockVol = [] # list of stock quantity available on market
>
> Using lists as class variables is a very good way to create very
> surprising bugs. Consider the following:
[snip]


Don't you think that the class attributes are *supposed* to be shared by
all instances? In that case the behaviour you show is not a bug at all.


--
Steven

==============================================================================
TOPIC: Is there any library for indexing binary data?
http://groups.google.com/group/comp.lang.python/t/73b172b8c5c572ff?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Mar 24 2010 9:29 pm
From: "Gabriel Genellina"


En Thu, 25 Mar 2010 00:28:58 -0300, 甜瓜 <littlesweetmelon@gmail.com>
escribió:

> Recently, I am finding a good library for build index on binary data.
> Xapian & Lucene for python binding focus on text digestion rather than
> binary data. Could anyone give me some recommendation? Is there any
> library for indexing binary data no matter whether it is written in
> python?
>
> In my case, there is a very big datatable which stores structured
> binary data, eg:
> struct Item
> {
> long id; // used as key
> double value;
> };
>
> I want to build the index on "id" field to speed on searching. Since
> this datatable is not constant, the library should support incremental
> indexing. If there is no suitable library, I have to do the index by
> myself...

What about a database?

--
Gabriel Genellina

== 2 of 2 ==
Date: Wed, Mar 24 2010 10:53 pm
From: 甜瓜


Well, Database is not proper because 1. the table is very big (~10^9
rows) 2. we should support very fast *simple* query that is to get
value corresponding to single key (~10^7 queries / second).

Currently, I have implemented a specific algorithm to deal with my
problem. However, I want to employ some library to simplify codings,
otherwise I have to write my own code for each big table. It is
possible that, after using indexing library, the program cannot run as
fast as homemade code. But if it can greatly simplify my job and can
provide satisfied speed (eg 10^5~10^6 queries / second), the indexing
library is still a good choice for me.

--
ShenLei

2010/3/25 Gabriel Genellina <gagsl-py2@yahoo.com.ar>:
> En Thu, 25 Mar 2010 00:28:58 -0300, 甜瓜 <littlesweetmelon@gmail.com>
> escribió:
>
>> Recently, I am finding a good library for build index on binary data.
>> Xapian & Lucene for python binding focus on text digestion rather than
>> binary data. Could anyone give me some recommendation? Is there any
>> library for indexing binary data no matter whether it is written in
>> python?
>>
>> In my case, there is a very big datatable which stores structured
>> binary data, eg:
>> struct Item
>> {
>> long id; // used as key
>> double value;
>> };
>>
>> I want to build the index on "id" field to speed on searching. Since
>> this datatable is not constant, the library should support incremental
>> indexing. If there is no suitable library, I have to do the index by
>> myself...
>
> What about a database?
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

==============================================================================
TOPIC: sum for sequences?
http://groups.google.com/group/comp.lang.python/t/139c0887a359405b?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Mar 24 2010 11:50 pm
From: TomF


On 2010-03-24 14:07:24 -0700, Steven D'Aprano
<steven@REMOVE.THIS.cybersource.com.au> said:
> On Wed, 24 Mar 2010 15:29:07 +0000, kj wrote:
>
>> Is there a sequence-oriented equivalent to the sum built-in? E.g.:
>>
>> seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6)
>>
>> ?
>
> Yes, sum.
>
> help(sum) is your friend.

You might not want to be so glib. The sum doc sure doesn't sound like
it should work on lists.

Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start' (which defaults to 0).

-Tom

==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate