Re: Why are tuples immutable?

2004-12-31 Thread Antoon Pardon
On 2004-12-29, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
>> Op 2004-12-23, Scott David Daniels schreef <[EMAIL PROTECTED]>:
>>>This is half the problem.  In the period where an element is in the
>>>wrong hash bucket, a new entry for the same value can be created in
>>>the proper hash bucket.  Then the code will have to determine how to
>>>merge two entries at rehash time.
>> 
>> But similar problems can happen in a sorted list, where the sort
>> is done on a "key" of the data and where you don't want duplicate
>> "keys".
>> 
>> If you then mutate a "key", it may be possible to insert a duplicate
>> "key" in the sorted list because the list isn't sorted anymore. If
>> you then resort your list you also have to determine how to merge
>> the two items with the same "key"
> I'd say this is a stretch.  The "key" argument to sort is very new, and
> it is a function from data to a value.  The "key" can be mutated only if
> the key function is picking out a mutable part of a data element.

You could give a comparison function to the sort method since at least
version 1.4. Allowing one to sort only on part of the data or a "key".

>> This just to show that repairing sorted lists can be just as
>> troublesome as repairing dictionaries. People who think 
>> sorted lists of mutable objects is less bothersome as dictionaries
>> with mutable keys, haven't thought things through IMO.
>
> But Python has no "sorted list" data type, so it is perfectly reasonable
> to expect such lists to go through transitional representations.

Dictionaries go through transitional representations too. 
I don't see the difference here.

> A set
> should not briefly have duplicate elements, a list should not vary in 
> length when elements are replaced, an integer being continuously
> incremented should not be viewable from a separate thread as anything
> but monotonicly increasing; dictionaries are primitives and should not
> have observable transitional states.

Well a sorted list, shouldn't be temporarily unsorted. Whether that
is a primitive or not doesn't matter. Either you have some invariant
in mind that mustn't be violated or not and user invariant can be just
as important as language invariants. Are you argueing that people
should only sort immutables or should only put immutabels in a
heapqueue. If not and you see nothing wrong with people sorting
mutable objects and require the discipline of the user to not
mutate such objects, then I don't see why we simply can't expect
the same discipline from users who want mutatable objects as keys.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes:
> Well, Google's market capitalization must be around 50 billion dollars
> or more, in the range of the top-100 companies, I believe, and they've
> never kept their Python use a secret.  

They use Python for a lot of internal tools but their high-volume
services are written in C++.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: The Industry choice

2004-12-31 Thread Walter S. Leipold
Paul Rubin writes:
> I don't know that C# is really that much different from Python.  
> I haven't used it but I have the impression that it's sort of similar
> under the skin. 

Nope nope nope.  C# is a statically typed, statically compiled (i.e., no
eval(...) or exec(...)), single-inheritance langauge with a
bondage-and-discipline syntax almost identical to Java's.  It compiles to
run on the Common Language Runtime, which is conceptually similar to the
JVM.  

Other than some syntactic sugar, C#'s primary difference from the latest
Java (v1.5) is that its standard libraries (the .Net stuff) are much poorer
-- this is particularly noticeable in its Collections API.  

-- Walt

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: novice regular expression question

2004-12-31 Thread It's me
Oops!

Sorry, didn't realize that.

Thanks,

"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> It's me wrote:
> > The shlex.py needs quite a number of .py files.  I tried to hunt down
> a few
> > of them and got really tire.
> >
> > Is there one batch of .py files that I can download from somewhere?
> >
> > Thanks,
> Not sure what you mean by this.
> Shlex is a standard library module.
> It imports os and sys only, they are standard library modules.
> If you have python you have them already.
> If you mean cStringIO it is in the standard library(at least on my
> system).
> You dont have to use it just feed shlex an open file.
> py>lexer = shlex.shlex(open('myrecord.txt', 'r'))
>
> Hth,
> M.E.Farmer
>


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Alex Martelli
Paul Rubin  wrote:

> [EMAIL PROTECTED] (Alex Martelli) writes:
> > Well, Google's market capitalization must be around 50 billion dollars
> > or more, in the range of the top-100 companies, I believe, and they've
> > never kept their Python use a secret.  
> 
> They use Python for a lot of internal tools but their high-volume
> services are written in C++.

I thought the "webcrawling" and updating of the indices/databases/caches
(high-volume, but not latency-critical) was coded in Python, the
latency-critical part (essentially that where every fraction of a second
counts, because a human user might be waiting for an answer), such as
queries to those DBs, in C++ -- based on the idea that you can "always"
(well, if you've got the right underlying data structures, of course,
and if the problems you're solving are as "embarassingly parallel" as
these would seem to be) enhance throughput by throwing more HW at the
problem, but latency doesn't yield to such treatment.  But, I could be
wrong, of course; I don't recall where I may have read these details,
and the throughput vs latency issue is a well-known general
consideration, so I may simply have "bridged" these in my mind.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what would you like to see in a 2nd edition Nutshell?

2004-12-31 Thread JanC
JoeG schreef:

> I disagree with your Tkinter vs. wxPython
> decision.  I tried a number of programs written with Tkinter and really
> didn't like the interface.  The program I helped develop is Windows
> based and I knew that a program with the Tkinter interface would never
> work as a cross platform environment.  Out existing customers just
> wouldn't accept it.   I can't see anyone using Tkinter for new mass
> market development.  If you've already got an application written with
> it you might want to continue using it but for new projects, wxPython
> seems to have some BIG advantages.

Robin Dunn is writing a wxPython book:



-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Using Tix and Tkinter

2004-12-31 Thread Harlin Seritt
I am trying to create a simple window using the following code:

--code---

import Tix
from Tkconstants import *
from Tkinter import *

root = Tix.Tk()

Label(root, text="Hello!").pack()
Tix.tixControl().pack()

root.mainloop()

---code---

When I run this, I get the following error:

Traceback (most recent call last):
  File "TixTest.py", line 8, in ?
Tix.tixControl().pack()
AttributeError: 'module' object has no attribute 'tixControl'

Any reason why I am not able to pull up this widget to work with it?

Thanks,

Harlin Seritt


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More baby squeaking - iterators in a class

2004-12-31 Thread Terry Reedy

"Bulba!" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Thanks to everyone for their responses, but it still doesn't work re
> returning next() method:

> class R3:
>def __init__(self, d):
>self.d=d
>self.i=len(d)
>def __iter__(self):
>d,i = self.d, self.i
>while i>0:
>i-=1
>yield d[i]
>
 p=R3('eggs')
 p.next()

This is the wrong test for what I and some others thought you were asking. 
The requirement for p to be an *iterable* and useable in code such as 'for 
i in p' is that iter(p), not p itself, have a .next method, and iter(p) 
will.  Try ip=iter(p) followed by ip.next and ip.next() instead.

If, for whatever reason, you instead want p to actually be an *iterator* 
with a .next (or .getitem) method, then, of course, you have to actually 
give it a .next (or .getitem) method.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Alex Martelli wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
(2) lambda a: a.lower()
My first thought here was to use str.lower instead of the lambda, but of
course that doesn't work if 'a' is a unicode object:

Right, but string.lower works (after an 'import string').  More
generally, maybe it would be nice to have a way to say "call a method on
x" without x's type being checked, just like attrgetter says "fetch an
attribute on x" -- say s/thing like:
def methodcaller(method_name, *a, **k):
def callit(x):
return getattr(x, method_name)(*a, **k)
callit.__name__ = method_name
return callit
Yeah, that's exactly the kind of thing I was looking for.  Very nice!
(3)  self.plural = lambda n: int(n != 1)
Note that this is *almost* writable with def syntax.  If only we could do:
def self.plural(n):
int(n != 1)

Not sure about the context, but maybe we could use, at class-level:
@staticmethod
def plural(n):
return int(n != 1)
The context was within the _parse method of GNUTranslations.  Basically, 
this method uses the fp passed in and a bunch of conditionals to 
determine how to define the plural method.  So I don't think it can be 
done at the class level.  Also, doesn't the assignment:
self.plural = lambda n: int(n != 1)
make this more like (at class level):
def plural(self, n):
return int(n != 1)
that is, isn't this an instance method, not a staticmethod?

py> class C(object):
... def __init__(self):
... self.plural = lambda n: int(n != 1)
...
py> c = C()
py> c.__class__.plural(1)
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: type object 'C' has no attribute 'plural'
py> c.plural(1)
0
Even though a good number of lambda uses may be avoidable or removable
by such means, I think there's just slightly too much variety -- in some
cases, a def with a name will have to be best
Yup, that was my feeling.  I was only able to rewrite as an expression 
about 50% of the lambdas that I found.  However, I (personally) don't 
have much of a problem with adding a def in most of the other cases. 
The only ones that make me a little nervous are examples like:

inspect.py: def formatargspec(args, varargs=None, varkw=None,
  ...
  formatvarargs=lambda name: '*' + name,
  formatvarkw=lambda name: '**' + name,
  formatvalue=lambda value: '=' + repr(value),
where the lambdas are declaring functions as keyword arguments in a def. 
   I'm not sure how much I like adding to the module multiple function 
defs that are really intended to be accessed only within formatargspec. 
 Still, were lambda to go away in Python 3000, it certainly wouldn't be 
the end of the world. ;-)

Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread Reinhold Birkenfeld
M.E.Farmer wrote:
> As I noted before shlex requires a file like object or a open file .
> py> import shlex
> py> a = shlex.shlex('fgfgfg dgfgfdgfdg')
> py> a.get_token()
> Traceback (most recent call last):
> File "", line 1, in ?
> File ".\shlex.py", line 74, in get_token
> raw = self.read_token()
> File ".\shlex.py", line 100, in read_token
> nextchar = self.instream.read(1)
> AttributeError: 'str' object has no attribute 'read'

Which Python version are you using?

The docs say that since Py2.3 strings are accepted.

regards,
Reinhold
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More baby squeaking - iterators in a class

2004-12-31 Thread Steven Bethard
Bulba! wrote:
Thanks to everyone for their responses, but it still doesn't work re
returning next() method:
class R3:
def __init__(self, d):
self.d=d
self.i=len(d)
def __iter__(self):
d,i = self.d, self.i
while i>0:
i-=1
yield d[i]


p=R3('eggs')
p.next()

[snip]
What's strange is that when it comes to function, it does return
the .next method:
def rev(d):
for i in range (len(d)-1, -1, -1):
yield d[i]


o=rev('eggs')

[snip]

o.next()
's'
Note the difference here.  When you're using the function, you call the 
iter function (called rev in your example).  When you're using the 
class, you haven't called the iter function, only instantiated the class 
(i.e. called the __init__ function).  Try one of the following:

py> p = R3('eggs')
py> i = p.__iter__()
py> i.next()
's'
or
py> p = R3('eggs')
py> i = iter(p)
py> i.next()
's'
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread It's me
I am right in the middle of doing text parsing so I used your example as a
mental exercise.   :-)

Here's a NDFA for your text:

   b  0 1-9 a-Z ,  . +  -   '   " \n
S0: S0 E   E  S1  E E E S3 E S2  E
S1: T1 E   E  S1  E E E  E  E  E T1
S2: S2 E   E  S2  E E E  E  E T2  E
S3: T3 E   E  S3  E E E  E  E  E T3

and the end-states are:

E: error in text
T1: You have the words: moo, cow
T2: You get "farmer john" (w quotes)
T3: You get zug

Can't gurantee that I did it right - I did it really quick - and it's
*specific* to your text string.

Now just need to hire a programmer to write some clean Python parsing code.
:-)

--
It's me





"Freddie" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Happy new year! Since I have run out of alcohol, I'll ask a question that
I
> haven't really worked out an answer for yet. Is there an elegant way to
turn
> something like:
>
>  > moo cow "farmer john" -zug
>
> into:
>
> ['moo', 'cow', 'farmer john'], ['zug']
>
> I'm trying to parse a search string so I can use it for SQL WHERE
constraints,
> preferably without horrifying regular expressions. Uhh yeah.
>
>  From 2005,
>Freddie
>



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More baby squeaking - iterators in a class

2004-12-31 Thread M.E.Farmer
Terry Reedy wrote:
>This is the wrong test for what I and some others thought you were
asking.
>The requirement for p to be an *iterable* and useable in code such as
'for
>i in p' is that iter(p), not p itself, have a .next method, and
iter(p)
>will. Try ip=iter(p) followed by ip.next and ip.next() instead.
Does that mean if you dont't call iter(() on your instance or have a
next() method you can't do this:
> class R3:
>def __init__(self, d):
>self.d=d
>self.i=len(d)
>def __iter__(self):
>d,i = self.d, self.i
>while i>0:
>i-=1
>yield d[i]

 p=R3('eggs')
 for i in p:
print i

I am asking because I want to fully understand what makes an
*iterator*. 

M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread beliavsky
Bulba wrote:
>OK, so what projects and why would you consider
>Python:
>1. "clearly unsuitable"

Large-scale scientific computing projects, such as numerical weather
prediction, where performance is critical. Python could be used as the
"glue" but not the "guts", where Fortran 95 and C++ are more
appropriate. In my tests, some posted here, there has been a
significant speed differential between Fortran 95 and Python with
Numeric. I don't know if using Numarray instead would change the
results.

Calling an extension written in C, such as Numeric, can improve
performance greatly over using "pure" Python, but the speed of
evaluating simple expressions can still be close to 2 orders of
magnitude slower.

Here is an example that computes
(1) sum(x)
(2) sum(x**2)
(3) sum((x-0.5)**2)

for 1E7 uniformly distributed random numbers.

# Python
from RandomArray import random
from timeimport time
from Numeric import sum
n= 1000
half = 0.5
x= random(n)
for iopt in range(1,4):
t1 = time()
if (iopt == 1):
xsum = sum(x)
elif (iopt == 2):
xsum = sum(x**2)
elif (iopt == 3):
xsum = sum((x-half)**2)
t2 = time()
print iopt,xsum,t2-t1

! Fortran 95
program xsum_power
implicit none
integer, parameter :: n = 1000
real(kind=8)   :: x(n),xsum,t1,t2
real   , parameter :: half = 0.5
integer:: iopt
iopt = 1
call random_seed()
call random_number(x)
do iopt=1,3
call cpu_time(t1)
select case (iopt)
case (1) ; xsum = sum(x)
case (2) ; xsum = sum(x**2)
case (3) ; xsum = sum((x-half)**2)
end select
call cpu_time(t2)
write (*,"(i4,100f16.6)") iopt,xsum,t2-t1
end do
end program xsum_power

The approximate times taken in seconds, in Python and Fortran, are

task  Fortran   Python
sum(x)  0.05   0.1
sum(x**2)  0.05   2.4
sum((x-0.5)**2)  0.05   3.2

In the Fortran code, essentially all the time is spent accessing the
array elements. Powers and subtractions in array operations seem to be
free in Fortran but very expensive in Python with Numeric.

Not wanting to be guilty of "premature optimization", I did not try to
make either code more efficient than my first attempt. The Fortran
compiler is Compaq Visual Fortran 6.6c, and the Python used is 2.2.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote:

> >>(3)  self.plural = lambda n: int(n != 1)
> >>Note that this is *almost* writable with def syntax.  If only we could do:
> >> def self.plural(n):
> >> int(n != 1)
> > 
> > Not sure about the context, but maybe we could use, at class-level:
> > @staticmethod
> > def plural(n):
> > return int(n != 1)
> 
> The context was within the _parse method of GNUTranslations.  Basically,
> this method uses the fp passed in and a bunch of conditionals to 
> determine how to define the plural method.  So I don't think it can be

Ah, OK -- I see, then you're probably quite right here!

> done at the class level.  Also, doesn't the assignment:
>  self.plural = lambda n: int(n != 1)
> make this more like (at class level):
>  def plural(self, n):
>  return int(n != 1)
> that is, isn't this an instance method, not a staticmethod?

Apart from the different possible definitions (which are of course
crucial), I don't see that.  Given the fact that, if you define plural
as an instancemethod, you're not using 'self' anyway, what usage would
break with a staticmethod?  "Doesn't use 'self'" smells more like a
staticmethod to me, even if you always call it on an instance.

> py> class C(object):
> ... def __init__(self):
> ... self.plural = lambda n: int(n != 1)
> ...
> py> c = C()
> py> c.__class__.plural(1)
> Traceback (most recent call last):
>File "", line 1, in ?
> AttributeError: type object 'C' has no attribute 'plural'
> py> c.plural(1)
> 0

This shows that staticmethod has slightly wider applicability, yes, but
I don't see this as a problem.  IOW, I see no real use cases where it's
important that hasattr(C, 'plural') is false while hasattr(C(),
'plural') is true [I could of course be missing something!].


Alex
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread M.E.Farmer
Ah! that is what the __future__ brings I guess.
Damn that progress making me outdated ;)
Python 2.2.3 ( a lot of  extensions I use are stuck there , so I still
use it)
M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Probleme mit der Installation der openSource Bittorrent.... python vs JAVA

2004-12-31 Thread JanC
Gerhard Haering schreef:

> I can understand your emotions here. OTOH it's typical for Germans
> (and even more so French) to assume that everybody speaks their
> language.

The same is true for English language speakers in my experience...
(E.g.: why is this international newsgroup in English only?)

> [*] The very minimum of netiquette would require to read a few
> messages in the newsgroup/mailing list and check what it is about and
> in what language it is.

Hm, be.* newsgroups are officially "quadrilingual" (Dutch, French, German 
& English), but in practice 99,99% of the messages are in Dutch, so 
reading a few messages won't help much...  ;-)

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed ain't bad

2004-12-31 Thread Bulba!
On 31 Dec 2004 06:05:44 -0800, Paul Rubin
 wrote:

>> (initially, that was just a shell script, but whitespaces and 
>> strange chars that users love to enter into filenames break
>> just too many shell tools)

>I didn't look at your script, but why not just use info-zip?

Because I need the users to be able to access the folder
tree with old versions of files, not the one big zipfile -- which 
they can't search for their old files using standard Windows 
explorer for instance.



--
It's a man's life in a Python Programming Association.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Alex Martelli wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
py> class C(object):
... def __init__(self):
... self.plural = lambda n: int(n != 1)
...
py> c = C()
py> c.__class__.plural(1)
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: type object 'C' has no attribute 'plural'
py> c.plural(1)
0

This shows that staticmethod has slightly wider applicability, yes, but
I don't see this as a problem.  IOW, I see no real use cases where it's
important that hasattr(C, 'plural') is false while hasattr(C(),
'plural') is true [I could of course be missing something!].
True, true.  I guess I was just wrapped up in reproducing the class 
behavior.  Making it available as a staticmethod of the class would of 
course only add functionality, not remove any.

Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: More baby squeaking - iterators in a class

2004-12-31 Thread Bulba!
On Fri, 31 Dec 2004 16:31:45 GMT, Steven Bethard
<[EMAIL PROTECTED]> wrote:

>py> p = R3('eggs')
>py> i = p.__iter__()
>py> i.next()
>'s'

>or

>py> p = R3('eggs')
>py> i = iter(p)
>py> i.next()
>'s'

And that is precisely what I needed to know. Thanks, to you,
Terry and everyone who took time to look at it.



--
It's a man's life in a Python Programming Association.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread JanC
Paul Rubin schreef:

> Java code is larger and takes longer to write, but has a higher chance
> of working properly once it compiles and passes basic tests. 

That's why you can make most JSP sites useless by disabling cookies in 
your browser?   :-p


-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Alex Martelli
Paul L. Du Bois <[EMAIL PROTECTED]> wrote:
   ...
> are all unsupported.  I'm sorry if google groups eats my leading
> whitespace; I've one-lined things to reduce the effect.

It does/did, so let me repost while fixing it since this is truly,
deliciously evil:

> def fn(gen):
> """Turns a generator expression into a callable."""
> def anonymous(*args): return gen.next()
> return anonymous
> 
> def args():
> """Works with fn(); yields args passed to anonymous()."""
> while True: yield sys._getframe(2).f_locals['args']
> 
> args = args()
> 
> foo = fn(a + b * c for (a,b,c) in args)
> assert foo(3,4,5) == 3+4*5
> assert foo(4,5,6) == 4+5*6

Paul, you really SHOULD have posted this BEFORE I had to send in the
files for the 2nd ed's Coobook... this gets my vote for the most
delightful abuse of sys._getframe even (and I've seen quite a few;-).

Kudos!!!


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> array elements. Powers and subtractions in array operations seem to be
> free in Fortran but very expensive in Python with Numeric.

Right, particularly raising to power: a good part of your observations
(not all) is accounted for by the fact that Python doesn't perform
strength reduction.  Taking a trivial example (everything is slow since
I'm using a laptop in lowpower mode, but the ratio is meaningful):

kallisti:/tmp alex$ /usr/bin/python timeit.py -s'import Numeric;
xs=Numeric.ones(999); sum=Numeric.sum' 'sum(xs*xs)'
1 loops, best of 3: 67.2 usec per loop

kallisti:/tmp alex$ /usr/bin/python timeit.py -s'import Numeric;
xs=Numeric.ones(999); sum=Numeric.sum' 'sum(xs**2)'
1000 loops, best of 3: 835 usec per loop


I guess this plays to the strengths of old fogeys like me -- having
grown up in a world where even good (-for-the-time) Fortran compilers
(!) often didn't do strength reduction, it just wouldn't _occur_ to me
to write x**2 where I mean x*x.  ((Memo to self: point this out in the
Optimization section of the Nutshell's 2nd ed, since it IS a reasonably
frequent performance trap)).  I remember once working with a good
scientist, back in the early 80's, on getting good running times for his
Fortran program coming from some (I believe) CDC machine to an IBM
mainframe, and achieving almost an order of magnitude worth of gain in
some important function by doing manual strength reduction in just a few
statements; apparently the CDC Fortran compiler _did_ do strength
reduction (I don't recall whether it was specifically x**2 -> x*x).

I believe, but I don't have one at hand to check, that scipy.weave may
be better in this regard.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyUnitPerf

2004-12-31 Thread Dieter Maurer
"Grig" <[EMAIL PROTECTED]> writes on 28 Dec 2004 18:47:45 -0800:
> ...
> My own experience with pyUnit has been very satisfactory and for me
> personally pyUnitPerf scratches an itch.

We use "pyUnit" extensively and are mostly satisfied.

There is one essential problem we hit more often: setting up
and tearing down can take excessive time.
Often, we are forced to abandon the test independence
and let a complete set of tests share the main part of the fixture.


--
Dieter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQT installation

2004-12-31 Thread Alex Martelli
Jarek Zgoda <[EMAIL PROTECTED]> wrote:

> Nanoscalesoft wrote:
> 
> > does that mean PyQT is not forward What a bad thing is this...
> 
> Whoa, how did you get it?
> 
> You can buy commercial licenses and be as current as we are on Linux 
> with GPL versions of Qt+PyQt. Oh, and QScintilla and Eric3!

MacOSX, too.  And it's COOL to program (haven't looked at all into 4.0
yet -- I'm mostly talking about 3.*)... I dunno, its programming model
just appears to fit my brain very well, I guess.

BTW: used to be that the cheapest way to get commercial licenses for Qt
use from Python only (i.e. if you didn't care to write C++ code for it
anyway) was to purchase BlackAdder -- a usable IDE by itself, btw,
though no doubt not as powerful in debugging as WingIDE.  I haven't
recently checked whether that is still true, however.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread Reinhold Birkenfeld
M.E.Farmer wrote:
> Ah! that is what the __future__ brings I guess.
> Damn that progress making me outdated ;)
> Python 2.2.3 ( a lot of  extensions I use are stuck there , so I still
> use it)

I'm also positively surprised how many cute little additions are there
every new Python version. Great thanks to the great devs!

Reinhold
-- 
http://mail.python.org/mailman/listinfo/python-list


OT: spacing of code in Google Groups

2004-12-31 Thread beliavsky
When I copy code from a source file into a Google Groups message, the
indentation is messed up, making my Python code illegal and all my code
ugly. Are there tricks to avoid this?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQT installation

2004-12-31 Thread Alex Martelli
Steve Holden <[EMAIL PROTECTED]> wrote:

> I presume the non-commercial edition is for people who want to use Qt
> but don't want to pay licensing fees or open their source? Or is the GPL
> version only available on non-Windows platforms? Of all the GUI 
> platforms I know about, Qt certainly has the murkiest licensing picture.

I don't find it murky, myself: GPL is available for good platforms (such
as MacOSX and Linux), if you insist on using/releasing for Windows, you
have to pay, period.  

Non-commercial edition is NOT for release or ANY commercial use, just
for learning.

Basically: if you want it on Windows for free, forget Qt (I hear the
cygwin people are trying to make a GPL Qt available for Win+cyg+XFree,
but I suspect trolltech ain't happy about that -- anyway, I don't think
it would be "native", X11 being still required).  That's how Trolltech
chooses to finance their development -- make money from firms which want
to release for Windows (or ones which want to release closed-source for
Unix or Mac, but I suspect there's few of the latter), use some part of
that money to support and encourage free software on free platforms or
platforms _close enough_ to free (Mac OS X itself ain't free -- but its
underpinnings, Darwin, are... a nice variant on open-source BSD...).

There _WERE_ (4 years ago? 5?) some licensing hassles, and some kind of
stand-off between Trolltech/Qt on one side and the FSF on the other
(which resulted in the birth of Gnome as an alternative to Qt-based KDE,
if I recall correctly).  But that WAS a long time ago, and now that the
GPL version is available (though not for Windows) and has been for quite
a while I'm pretty sure not even Stallman has bones to pick with
Trolltech's licensing any more.


Fairly or not, it does seem Trolltech is paying in terms of mindshare
for their not-for-free attitude to Windows among the
free-as-in-free-beer software crowd -- if a GPL version was available
for Windows I'm pretty sure PyQt would be the default de facto Python
GUI toolkit today, rather than having wx and Tk vie for the crown (with
GTK as a somewhat-distant third, it appears to me, and Qt nowhere in
sight because "it ain't free for Windows").  But really, there hasn't
been anything murky about it for _years_... take it or leave it, it's
rather clear and well-defined, it seems to me!


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

2004-12-31 Thread Alex Martelli
Cameron Laird <[EMAIL PROTECTED]> wrote:
   ...
>  Yippee!  The martellibot promises to explain Unicode for Pythoneers.
>  http://groups-beta.google.com/group/comp.lang.python/msg/6015a5a05c206712

Uh -- _did_ I?  Eeep... I guess I did... mostly, I was pointing to
Holger Krekel's very nice recipe (not sure he posted it to the site as
well as submitting it for the printed edition, but, lobby _HIM_ about
that;-).


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing metaclasses and exceptions

2004-12-31 Thread Alex Martelli
Phillip J. Eby <[EMAIL PROTECTED]> wrote:

> Jp Calderone wrote:
> >   I'd skip that, though.  Your problem doesn't sound "Metaclass!" at
> me.
> > I wonder if you could elaborate on your usage?  Perhaps there's a
> better
> > solution which doesn't involve metaclasses at all.
> 
> I suspect he could *maybe* get by without the metaclass, but not
> without custom descriptors, which don't always work for classic
> classes.  In particular, if a Java exception has a static method, he'll
> want to map that to a Python classmethod or staticmethod, and as far as
> I recall, that stuff just doesn't work with classic classes.

I believe they work fine:

>>> class sic: 
...   @staticmethod
...   def hello(): print "Hello world"
... 
>>> sic.hello()
Hello world


Class-sick classes have many little niggling problems, but I think
staticmethod and classmethod aren't among them.


> In particular, if a Java class has both a static method and a
> non-static method of the same name, there's no way that I know of to
> map it into Python using a classic class; you *have* to have a
> metaclass with a data descriptor in order to prevent a __dict__ lookup
> on the class itself.

Well, that's another ball of wax.  Does Java support that kind of
overloading...?!  Eeek.  I believe C++ doesn't and for once is simpler
thereby.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Steven Bethard
Alex Martelli wrote:
Paul L. Du Bois <[EMAIL PROTECTED]> wrote:
def fn(gen):
   """Turns a generator expression into a callable."""
   def anonymous(*args): return gen.next()
   return anonymous
def args():
   """Works with fn(); yields args passed to anonymous()."""
   while True: yield sys._getframe(2).f_locals['args']
args = args()
foo = fn(a + b * c for (a,b,c) in args)
assert foo(3,4,5) == 3+4*5
assert foo(4,5,6) == 4+5*6

Paul, you really SHOULD have posted this BEFORE I had to send in the
files for the 2nd ed's Coobook... this gets my vote for the most
delightful abuse of sys._getframe even (and I've seen quite a few;-).
So, I couldn't figure out why this worked until I started to write an 
email to ask.  Once I understood it, I figured it wouldn't hurt to send 
my thoughts out anyway to (1) verify that I understand it right, and (2) 
help anyone else who was trying to figure this out.

As I understand it sys._getframe(2).f_locals should get the names local 
to the stack frame two above the current one.  So, in the context of:
fn(... for ... in args)
sys._getframe(2).f_locals should be looking at the names local to the 
'anonymous' function in the 'fn' function, because one stack frame up 
from the 'args' function is the generator's 'next' function, and two 
stack frames up is the 'anonymous' function.  That means that:
sys._getframe(2).f_locals['args']
gets whatever object has been bound to 'args' in:
def anonymous(*args):
So then in:
foo = fn(a + b * c for (a,b,c) in args)
foo(3,4,5)
foo(4,5,6)
sys._getframe(2).f_locals['args'] will get (3, 4, 5) in the first foo 
call, (4, 5, 6) in the second foo call, etc.

So basically the way a call like foo(3, 4, 5) works is:
(1) foo(3, 4, 5) calls gen.next() where gen is the generator expression
(2) gen.next() calls args.next()
(3) args.next() returns the (3, 4, 5) argument tuple of foo by looking 
up the stack frames
(4) gen.next() binds (3, 4, 5) to the names a, b, c respectively
(5) gen.next() returns the value of "a + b * c" for these bindings
(6) foo(3, 4, 5) returns the same value (as gen.next() did)

Does that seem about right?
Steve
P.S.  That's so *evilly* cool!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Scott David Daniels
David Bolen wrote:
So for example, an asynchronous sequence of operations might be like:
d = some_deferred_function()
d.addCallback(lambda x: next_function())
d.addCallback(lambda blah: third_function(otherargs, blah))
d.addCallback(lambda x: last_function())
which to me is more readable (in terms of seeing the sequence of
operations being performed in their proper order), then something like:
def cb_next(x):
return next_function()
def cb_third(blah, otherargs):
return third_function(otherargs, blah)
def cb_last(x):
return last_function()
d = some_deferred_function()
d.addCallback(cb_next)
d.addCallback(cb_third, otherargs)
d.addCallback(cb_next)

which has an extra layer of naming (the callback functions), and
requires more effort to follow the flow of what is really just a simple
sequence of three functions being called.
But this sequence contains an error of the same form as the "fat":
while test() != False:
 ...code...
The right sequence using lambda is:
 d = some_deferred_function()
 d.addCallback(next_function)
 d.addCallback(lambda blah: third_function(otherargs, blah))
 d.addCallback(last_function)
And I would write it as:
 def third_function_fixed_blah(blah):
 def call_third(otherargs):
 return third_function(otherargs, blah)
 return call_third
 d = some_deferred_function()
 d.addCallback(next_function)
 d.addCallback(third_function_fixed_blah, otherargs)
 d.addCallback(last_function)
The name gives you the chance to point out that the argument order is
tweaked.  In many such cases, I use curry (ASPN recipe #52549), which
should show up in Python as "partial" in the "functional" module
according to PEP 309 
(accepted but not included).  I suppose it will show up in Python 2.5.
Programming is a quest is for clear, easy-to-read code, not quick,
easy-to-write code.  Choosing a name is a chance to explain what you
are doing.  lambda is used too often in lieu of deciding what to write.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote:

> Does that seem about right?

Yep!

> P.S.  That's so *evilly* cool!

We should have an Evilly Cool Hack of the Year, and I nominate Paul du
Bois's one as the winner for 2004.  Do I hear any second...?


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes:
> We should have an Evilly Cool Hack of the Year, and I nominate Paul du
> Bois's one as the winner for 2004.  Do I hear any second...?

The year's not over yet :).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Ian Bicking
David Bolen wrote:
Ian Bicking <[EMAIL PROTECTED]> writes:

The one motivation I can see for function expressions is
callback-oriented programming, like:
  get_web_page(url,
when_retrieved={page |
  give_page_to_other_object(munge_page(page))})

This is my primary use case for lambda's nowadays as well - typically
just to provide a way to convert the input to a callback into a call
to some other routine.  I do a lot of Twisted stuff, whose deferred
objects make heavy use of single parameter callbacks, and often you
just want to call the next method in sequence, with some minor change
(or to ignore) the last result.
So for example, an asynchronous sequence of operations might be like:
d = some_deferred_function()
d.addCallback(lambda x: next_function())
d.addCallback(lambda blah: third_function(otherargs, blah))
d.addCallback(lambda x: last_function())
Steven proposed an ignoreargs function, and the partial function offers 
the other side (http://www.python.org/peps/pep-0309.html).  So this 
would become:

d = some_deferred_function()
d.addCallback(ignoreargs(next_function, 1))
d.addCallback(partial(third_function, otherargs))
d.addCallback(ignoreargs(last_function, 1))
I'm not sure this is "better" than it is with lambda.  It's actually 
considerably less readable to me.  Hmm... well, that makes me less 
excited about those...

--
Ian Bicking  /  [EMAIL PROTECTED]  / http://blog.ianbicking.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-31 Thread Brian van den Broek
Hi all,
a question about using parenthesis for tuples veered very far off topic 
before I returned from a trip and found the thread. I've a comment on 
the original topic, and then a comment off-topic even for the off-topic 
direction in which the thread ended up :-)

The on-topic:
the use of '(' and ')' for tuples really did jar me. With a background 
in set-theory, I expected tuples to look like <1, 2, 3>. It took a 
little bit to reset my brain.

I am aware that even some set theory material is starting to use rounded 
brackets for tuples. With this I can cope (barely). But, just yesterday, 
I was reading an otherwise fine book on relevance logic marred by its 
use of both angle and round brackets for tuples, with no apparent 
principle other than the coin toss determining which to use when. The 
horror!

The off-topic**2:
Alex Martelli said unto the world upon 2004-12-30 19:09:

Have you heard of Villanova, often named as the birthplace of Italian
civilization?  That's about 15 km away, where I generally go for major
grocery shopping at a hypermarket when I _do_ have a car.

Alex
'Hypermarket' is a new one to me, but seems instantly understandable. It 
also makes me very sad.

Italy isn't my country, but for the past few years I've been lucky 
enough to spend a month or so in the north each year. In the short time 
I've been doing so, I think I've been able to detect the decline of the 
small independent shops and the rampant growth of the american style 
mall, big-box store and mutilplex.

The small store to which you can walk and where you likely know the 
vendor, and even if you don't, run the real risk of having a 
conversation, seems a thing worth trying to preserve. They surely aren't 
as efficient as the north-american model, but one of the nicest things 
about Italian culture IMHO is that it appears to understand that some 
things are at least as important as efficiency.

And it is truly heart-breaking to see the beautiful countryside around 
Italian towns being defaced by large fields of blacktop.

Luddites of the world unite!
Happy New Year to all,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread Andrew Dalke
"It's me" wrote:
> Here's a NDFA for your text:
> 
>b  0 1-9 a-Z ,  . +  -   '   " \n
> S0: S0 E   E  S1  E E E S3 E S2  E
> S1: T1 E   E  S1  E E E  E  E  E T1
> S2: S2 E   E  S2  E E E  E  E T2  E
> S3: T3 E   E  S3  E E E  E  E  E T3

Now if I only had an NDFA for parsing that syntax...

  :)
Andrew
[EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread David Bolen
Scott David Daniels <[EMAIL PROTECTED]> writes:

> David Bolen wrote:
> > So for example, an asynchronous sequence of operations might be like:
> > d = some_deferred_function()
> > d.addCallback(lambda x: next_function())
> > d.addCallback(lambda blah: third_function(otherargs, blah))
> > d.addCallback(lambda x: last_function())
> > which to me is more readable (in terms of seeing the sequence of
> > operations being performed in their proper order), then something like:
> > def cb_next(x):
> > return next_function()
> > def cb_third(blah, otherargs):
> > return third_function(otherargs, blah)
> > def cb_last(x):
> > return last_function()
> > d = some_deferred_function()
> > d.addCallback(cb_next)
> > d.addCallback(cb_third, otherargs)
> > d.addCallback(cb_next)
> > which has an extra layer of naming (the callback functions),
> > and
> > requires more effort to follow the flow of what is really just a simple
> > sequence of three functions being called.
> 
> But this sequence contains an error of the same form as the "fat":

"this" being which of the two scenarios you quote above?

>  while test() != False:
>   ...code...

I'm not sure I follow the "error" in this snippet...

> The right sequence using lambda is:
>   d = some_deferred_function()
>   d.addCallback(next_function)
>   d.addCallback(lambda blah: third_function(otherargs, blah))
>   d.addCallback(last_function)

By what metric are you judging "right"?

In my scenario, the functions next_function and last_function are not
written to expect any arguments, so they can't be passed straight into
addCallback because any deferred callback will automatically receive
the result of the prior deferred callback in the chain (this is how
Twisted handles asynchronous callbacks for pending operations).
Someone has to absorb that argument (either the lambda, or
next_function itself, which if it is an existing function, needs to be
handled by a wrapper, ala my second example).

Your "right" sequence simply isn't equivalent to what I wrote.
Whether or not next_function is fixable to be used this way is a
separate point, but then you're discussing two different scenarios,
and not two ways to write one scenario.

-- David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Scott David Daniels
David Bolen wrote:
Scott David Daniels <[EMAIL PROTECTED]> writes:
while test() != False:
 ...code...
I'm not sure I follow the "error" in this snippet...
The code is "fat" -- clearer is:
 while test():
  ...code...
The right sequence using lambda is:
 d = some_deferred_function()
 d.addCallback(next_function)
 d.addCallback(lambda blah: third_function(otherargs, blah))
 d.addCallback(last_function)
By what metric are you judging "right"?
By a broken metric that requires you to mis-understand the original code
in the same way that I did.  It was an idiotic response that required
more careful reading than I am doing this morning.  The thing I've seen
in too much code (and though I saw in your code) is code like:
   requires_function(lambda: function())
rather than:
   requires_function(function)
It happens quite often, and I'm sure you've seen it.  But I got your
code wrong, and for that I apologize.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread It's me

"Andrew Dalke" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" wrote:
> > Here's a NDFA for your text:
> >
> >b  0 1-9 a-Z ,  . +  -   '   " \n
> > S0: S0 E   E  S1  E E E S3 E S2  E
> > S1: T1 E   E  S1  E E E  E  E  E T1
> > S2: S2 E   E  S2  E E E  E  E T2  E
> > S3: T3 E   E  S3  E E E  E  E  E T3
>
> Now if I only had an NDFA for parsing that syntax...
>

Just finished one (don't ask me to show it - very clumpsy Python code -
still in learning mode).   :)

Here's one for parsing integer:

#   b 0 1-9 , . + - ' " a-Z \n
# S0: S0 S0 S1 T0 E S2 S2 E E E   T0
# S1: S3 S1 S1 T1 E E E E E E   T1
# S2: E S2 S1 E E E E E E E   E
# S3: S3 T2 T2 T1 T2 T2 T2 T2 T2 T2  T1

T0: you got a null token
T1: you got a good token, separator was ","
T2: you got a good token b, separator was " "
E: bad token


>   :)
> Andrew
> [EMAIL PROTECTED]
>


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-31 Thread Alex Martelli
Brian van den Broek <[EMAIL PROTECTED]> wrote:
   ...
> > Have you heard of Villanova, often named as the birthplace of Italian
> > civilization?  That's about 15 km away, where I generally go for major
> > grocery shopping at a hypermarket when I _do_ have a car.
> 
> 
> 
> > Alex
> 
> 'Hypermarket' is a new one to me, but seems instantly understandable. It
> also makes me very sad.

Ah, yes, I understand what you mean.

> Italy isn't my country, but for the past few years I've been lucky 
> enough to spend a month or so in the north each year. In the short time
> I've been doing so, I think I've been able to detect the decline of the
> small independent shops and the rampant growth of the american style 
> mall, big-box store and mutilplex.

To some extent, yes.  40 years ago, when I was a kid, I knew of about a
dozen small shops of each kind (butcher, baker, grocer, etc -- each
would sell only and strictly its specific wares; you'd go to different
specialized butchers for beef and pig, versus poultry, versus horsemeat,
etc; ...) which were well within walking distance, in addition to two
open-air markets.  Nowadays, living in the same place where I grew up, I
only know of about four small shops of each kind (but each does sell
more kinds of wares than of yore) and the same two markets (now with
some cover against rain, though still essentially open-air) -- plus
three minimarkets owned and managed by immigrants (so that when on
Christmas day I found out I was out of fruit juice, I _could_ easily
find an _open_ nearby store to buy more;-), and a mid-size supermarket.
But yes, all in all, there has been some noticeable reduction in the
number and variety of small nearby stores.

Many have been replaced by places selling takeaway pizza, falafel,
gyros, kebab, and the like -- considering that my home is very close to
the University quarter of town and the whole neighborhood has been
filling up with students living off campus for over 20 years, I find
that hardly surprising.  The typical student is far likelier to want a
ready-made, ready-to-eat kebab, than to buy the ingredients to prepare,
say, a pot roast.  People who do buy the latter, like me, are likelier
to plan in advance, to have a car, and to be willing to drive 20 minutes
or so to get to a hypermarket, for the small savings (compared to the
mid-sized supermarket that's walking distance) and the vaster choice
(only place I can get really good AND decent priced organic-grown
grapefruit juice, for example).

 
> The small store to which you can walk and where you likely know the 
> vendor, and even if you don't, run the real risk of having a 
> conversation, seems a thing worth trying to preserve. They surely aren't
> as efficient as the north-american model, but one of the nicest things
> about Italian culture IMHO is that it appears to understand that some
> things are at least as important as efficiency.

The falafel seller is quite as likely to start up a conversation as the
poultry-only butcher that used to be there 30 years ago, although
admittedly it does work better if you speak some rudiments of Arabic
(which, alas, I don't).  And the NA model, where it works right
(requiring _some_ density of population -- it just can't work right
where population is too thinly spread), offers you *choice*, just like
the variant that's growing in my part of Italy.  If you live in Old Palo
Alto, say, you get quite a choice of small shops and open-air markets
(with higher prevalence of organic produce than is common here yet) in
walking distance, as well as the ability to get into a car and go for
cheaper bulk shopping.  Of course, if you live in cheaper, more
spacious, endless-sprawling exurbia, there's *nothing* in walking
distance... that's the inevitable price of wanting that spaciousness,
see: it spreads things out.  Many Americans who can afford to do
otherwise would find it unbearably crowded to live in big apartment
buildings, as a vast majority of the population does here; yet if every
family had its own detached house, with garden and backyard, *boom*,
sprawl.  Geometry just won't be dictated to, see: multi-storied
apartment buildings and a scarcity of gardens is the flipside of the
population density which allows small walking-distance shops to thrive,
and, viceversa, hateful endless sprawl the flip side of everybody having
nice gardens etc.

All in all efficiency is best served by the Italian (and generally
European) preference for crowded cities of apartment buildings over
suburbia and exurbia -- we save a lot of driving that way.  But as my
long-term dream is STILL to restore grandfather's house in the
countryside and retire there, I can hardly speak against the desire for
space all around you;).

 
> And it is truly heart-breaking to see the beautiful countryside around
> Italian towns being defaced by large fields of blacktop.

The beautiful parts of Bologna's countryside (southwards, towards the
Appennines -- Bologna is halfway up on the footh

Re: Parsing a search string

2004-12-31 Thread Brian Beck
Freddie wrote:
I'm trying to parse a search string so I can use it for SQL WHERE 
constraints, preferably without horrifying regular expressions. Uhh yeah.
If you're interested, I've written a function that parses query strings 
using a customizable version of Google's search syntax.

Features include:
  - Binary operators like OR
  - Unary operators like '-' for exclusion
  - Customizable modifiers like Google's site:, intitle:, inurl: syntax
  - *No* query is an error (invalid characters are fixed up, etc.)
  - Result is a dictionary in one of two possible forms, both geared 
towards being input to an search method for your database

I'd be glad to post the code, although I'd probably want to have a last 
look at it before I let others see it...

--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread John Machin
Andrew Dalke wrote:
> "It's me" wrote:
> > Here's a NDFA for your text:
> >
> >b  0 1-9 a-Z ,  . +  -   '   " \n
> > S0: S0 E   E  S1  E E E S3 E S2  E
> > S1: T1 E   E  S1  E E E  E  E  E T1
> > S2: S2 E   E  S2  E E E  E  E T2  E
> > S3: T3 E   E  S3  E E E  E  E  E T3
>
> Now if I only had an NDFA for parsing that syntax...

Parsing your sentence as written ("if I only had"): If you were the
sole keeper of the secret??

Parsing it as intended ("if only I had"), and ignoring the smiley:
Looks like a fairly straight-forward state-transition table to me. The
column headings are not aligned properly in the message, b means blank,
a-Z is bletchworthy, but the da Vinci code it ain't.

If only we had an NDFA (whatever that is) for guessing what acronyms
mean ...

Where I come from:
DFA = deterministic finite-state automaton
NFA = non-det..
SFA = content-free
NFI = concept-free
NDFA = National Dairy Farmers' Association

HTH, and Happy New Year!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Paul Rubin   wrote:
>Peter Dembinski <[EMAIL PROTECTED]> writes:
>> If it has to be both reliable and secure, I suggest you used more
>> redundant language such as Ada 95.
>
>That's something to think about and it's come up in discussions, but
>probably complicates stuff since it's not currently available on the
>target platform.  Also, the people on the project have significant
>Java and Python experience but haven't used Ada.  Do you think it has
>real advantages over Java?

You have me curious, Paul; what's the platform which lacks an Ada95
compiler http://directory.google.com/Top/Computers/Programming/Languages/Ada/Compilers/ 
>?

Me, I think Ada has significant advantages over Java in safety, 
especially where OO is *not* a benefit (as is sometimes the case).

For a not-too-different variety of safety, I like Eiffel.  Again,
Eiffel compilers are available nearly, but not entirely, everywhere.

I'm not arguing for redundancy (see above), by the way, just precision.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Christopher Koppler  <[EMAIL PROTECTED]> wrote:
.
.
.
>Manager culture is still very much mired in rituals that may in one form
>or another go back to hunter-gatherer days (or maybe even further); that
>'the industry choice' is more often than not something backed by a *major*
>company is part of a ritual complex based on relations to the alpha male.
>Small companies ingratiate themselves with their perceived betters by
>using their products, even when technically far superior products would be
>available. When the 'market leader' produces a new toy, everyone who wants
>to be in his favor must use it _and_ also damn the toys available from any
>of those competing for leadership, viz. the ongoing state of cold war
>between Sun and MS and their respective worshipers. Toys that have not
>been sanctioned by the leader, or that are, even worse, de facto unknown
>to him, are met with ignorance, scorn, or even repression.
>
>[snip]
>> For Python a Big Thing would happen if some Major Vendor
>> embraced it as its Official Language(tm). Python language
>> itself could turn into a smoking crock the very next day, but
>> everybody who doesn't live under the rock would still be 
>> writing in it.
>
>The moral is, of course, that either the Python community's alpha geeks
>need to get access to controlling interest in a *major* company (or to
>become successful enough with their own companies to register on the
>current *major* companies radar as potential competition) or as you
>say, Python needs to be embraced like Linux was. That's the way to win the
>hearts of software companies' managers.
.
.
.
I like repeating the description which emphasizes culture
and phenotype over the rationality of business schools.

Let me add a cautionary note, though:  Big Companies, 
including Oracle, Software AG, IBM, Cisco, and so on, have
adopted Tcl over and over.  All of them still rely on Tcl
for crucial products.  All of them also have employees who
sincerely wonder, "Tcl?  Isn't that dead?"

I offer this as a counter-example to the belief that Adop-
tion by a heavyweight necessarily results in widespread
acceptance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re : Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-31 Thread Cedric
This is a 3 weeks old problem, but having found a solution (and having
looked for one here, finding only this message), I'm replying now.

From: Jive ([EMAIL PROTECTED])
Subject: Upgrade woes: Numeric, gnuplot, and Python 2.4 
Date: 2004-12-11 18:45:10 PST 
> Here's my sitch:
>
> I use gnuplot.py at work, platform Win32.  
> I want to upgrade to Python 2.4.
> Gnuplot.py uses extension module Numeric.  
> Numeric is now "unsupported." The documentation 
> says "If you are new to Numerical Python, please 
> use Numarray.".  It's not that easy, dangit.  
> The download page for numpy does not contain a 
> 2.4 version of Numeric, and I suspect they do 
> not intend to release one, because there IS a 2.4 
> version of Numarray.

Numarray was designed to be mostly backward compatible with Numeric. I
just replaced all of the

import Numeric

by

import numarray as Numeric

and it worked fine. Though I also had the same problem that I had with
Python 2.3 and Gnuplot, namely having to correct gnuplot_command in
gp_win32.py. On a related note, maybe I don't understand pipes, but
why doesn't popen() return an error when it doesn't find the file, and
it's open for reading?

Cédric
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyUnitPerf

2004-12-31 Thread Peter Hansen
Dieter Maurer wrote:
We use "pyUnit" extensively and are mostly satisfied.
There is one essential problem we hit more often: setting up
and tearing down can take excessive time.
Often, we are forced to abandon the test independence
and let a complete set of tests share the main part of the fixture.
That's not an issue with the framework, though, is it?
Just with your specific tests and application?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> When I copy code from a source file into a Google Groups message, the
> indentation is messed up, making my Python code illegal and all my
code
> ugly. Are there tricks to avoid this?

Try putting a # at the start of every line. Everyone should
understand what you mean (and you can always tell them to remove
the #'s once they copy the listing).

#import gmpy
#i = 7
#while i<10:
## conjecture 1
#
#   if ((i % 3)>0) and ((i % 5)>0):
#   f = gmpy.fib(i)
#   ip = gmpy.is_prime(i)
#   fm = f % i
#   if (fm==(i-1)) and (ip==0):
#   print "fib %5d: %5d (mod %5d)" % (i,fm,i),
#   print gmpy.is_prime(i)
#   i += 2
#
#"""
#Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
#   then i is prime
#
#run #1 print all fib(i) == i-1 (mod i) that are composite
#
#fib  5777:  5776 (mod  5777) 0 <-- counter example
#fib 10877: 10876 (mod 10877) 0 <-- counter example
#fib 17261: 17260 (mod 17261) 0
#fib 75077: 75076 (mod 75077) 0 <-- counter example
#fib 80189: 80188 (mod 80189) 0
#"""

Preview looked ok, so let's see what happens when I post it.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Hans Nowak
Paul Rubin wrote:
You should write unit tests either way, but in Python you're relying
on the tests to find stuff that the compiler finds for you with Java.
As I wrote on my weblog a while ago, I suspect that this effect is 
largely psychological.  You jump through hoops, declaring types all over 
the place, checking exceptions, working around the language's 
limitations, etc.  So when your code compiles, it *feels* safer.  Like 
you're at least part of the way towards ensuring correctness.  All that 
work must be good for *something*, right?  Never mind that when writing 
unit tests for a dynamic language, you don't check for these things at 
all.  How often do you explicitly check types in Python unit tests? 
IMHO, when using a dynamic language, you don't need most of the checks 
that Java, C# and their ilk force upon you.

--
Hans Nowak
http://zephyrfalcon.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Hans Nowak
Christopher Koppler wrote:
> --
> Christopher
>
> In theory, I'm in love with Lisp,
> but I hop into bed with Python every chance I get.
That reminds me of something my old math teacher used to say... "My wife 
is my cathedral, but I pray in every chapel." :-)

--
Hans Nowak
http://zephyrfalcon.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread Grant Edwards
On 2004-12-31, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>> When I copy code from a source file into a Google Groups
>> message, the indentation is messed up, making my Python code
>> illegal and all my code ugly. Are there tricks to avoid this?
>
> Try putting a # at the start of every line. Everyone should
> understand what you mean (and you can always tell them to remove
> the #'s once they copy the listing).
>
> #import gmpy
> #i = 7
> #while i<10:

I always rather liked line numbers (a-la 'can -n').  That also
makes discussion of the code easier:

 1  import gmpy
 2  i = 7
 3  while i<10:
 4  # conjecture 1
 5  
 6   if ((i % 3)>0) and ((i % 5)>0):
 7   f = gmpy.fib(i)
 8   ip = gmpy.is_prime(i)
 9   fm = f % i
10   if (fm==(i-1)) and (ip==0):
11   print "fib %5d: %5d (mod %5d)" % (i,fm,i),
12   print gmpy.is_prime(i)
13   i += 2
14  
15  """
16  Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
17 then i is prime
18  
19  run #1 print all fib(i) == i-1 (mod i) that are composite
20  
21  fib  5777:  5776 (mod  5777) 0 <-- counter example
22  fib 10877: 10876 (mod 10877) 0 <-- counter example
23  fib 17261: 17260 (mod 17261) 0
24  fib 75077: 75076 (mod 75077) 0 <-- counter example
25  fib 80189: 80188 (mod 80189) 0
26  """

Not sure what Google Groups does to it...

-- 
Grant Edwards   grante Yow!  Now I understand the
  at   meaning of "THE MOD SQUAD"!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote:
> [EMAIL PROTECTED] wrote:
> > When I copy code from a source file into a Google Groups message,
the
> > indentation is messed up, making my Python code illegal and all my
> code
> > ugly. Are there tricks to avoid this?
>
> Try putting a # at the start of every line. Everyone should
> understand what you mean (and you can always tell them to remove
> the #'s once they copy the listing).
>
> #import gmpy
> #i = 7
> #while i<10:
> ## conjecture 1
> #
> # if ((i % 3)>0) and ((i % 5)>0):
> # f = gmpy.fib(i)
> # ip = gmpy.is_prime(i)
> # fm = f % i
> # if (fm==(i-1)) and (ip==0):
> # print "fib %5d: %5d (mod %5d)" % (i,fm,i),
> # print gmpy.is_prime(i)
> # i += 2
> #
> #"""
> #Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
> #   then i is prime
> #
> #run #1 print all fib(i) == i-1 (mod i) that are composite
> #
> #fib  5777:  5776 (mod  5777) 0 <-- counter example
> #fib 10877: 10876 (mod 10877) 0 <-- counter example
> #fib 17261: 17260 (mod 17261) 0
> #fib 75077: 75076 (mod 75077) 0 <-- counter example
> #fib 80189: 80188 (mod 80189) 0
> #"""
>
> Preview looked ok, so let's see what happens when I post it.

In looking at this, I noticed the tabs in the code were preserved,
but the double space between "fib" and "5777" in the comments was
not. But if you click on the "show original" link, the spaces come
back, so maybe you don't to any thing except "show original" when
you want to copy source code.

Testing 1
 Testing 2
  Testing 3

-- 
http://mail.python.org/mailman/listinfo/python-list


Of closures and expressing anonymous functions [Was: Re: Securing a future for anonymous functions in Python]

2004-12-31 Thread Simo Melenius
[EMAIL PROTECTED] (Bengt Richter) writes:

> Closure is the name for the whole thing, apparently, not just the
> environment the procedure body needs, which was the aspect that I
> (mis)attached the name to.

Which brings me to the point where I'd welcome more flexibility in
writing to variables outside the local scope. This limitation most
often kicks in in closed-over code in function objects, although it's
a more general issue in Python's scoping.

As we know, you can't write to variables that are both non-local and
non-global (globals you can declare "global"). Now that effectively
makes free variables read-only (although, the objects they point to
can _still_ be mutated).

Allowing write access to variables in a closed-over lexical scope
outside the innermost scope wouldn't hurt because:

1) if you need it, you can already do it -- just practice some
   cumbersome tricks make suitable arrangements (e.g. the classical
   accumulator example uses an array to hold the counter value instead
   of binding it directly to the free variable;

2) if you don't need or understand it, you don't have to use it;

3) and at least in function instances: if you accidentally do, it'll
   change the bindings within your closure only which is definitely
   less dangerous than mutating objects that are bound inside the
   closure.

It must be noted, however, that such behaviour would change the way of
hiding nested variable names:

Now it's safe (though maybe lexically confusing) to use the same
variable names in inner functions. This could happen with common names
for temporary variables like "i", "x", "y".

On the other hand, one could introduce a way to declare variables from
global scope or from local scope, with default from lexical scope. (If
you want to explicitly hide an outer binding, you'd declare "local
foo", for example. You can already do "global foo".)

> I see what you are saying (I think), but I think I'd still like a
> full anonymous def, whatever adapter you come up with. And I prefer
> to be persuaded ;-)

I elaborated on this one in a post a few days ago. Indeed, it is
mostly a minor issue that _can_ be worked around(1). The problem is
that it eventually becomes irritating, when repeated all the time, to
name functions even if the name isn't used elsewhere.

It also creates an implicit dependency from the function call (one of
whose arguments points to the once-named function) to the once-named
function. That is, when you refactor some of your code, you must keep
two things paired all the time in your cut+paste maneuvers.


br,
S

(1) Everything can be worked around. In contrast: you can work around
the lack of a syntactic language by typing in machine code manually.
Sound stupid? Yes, it was done decades ago. How about using C to write
a "shell script" equivalent that you need, as a workaround to the
problem of lacking a shell? Stupid? Yes, but less -- it's been done.
How about writing callbacks by passing in a function pointer and a
data pointer, if you don't want to use a language like Python that
automates that task for you? Stupid? Yes, but not much -- it's been
done all the time. How about implementing an _anonymous_ function by
naming it, if you can't do it otherwise?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Paul Du Bois
Alex Martelli wrote:
> We should have an Evilly Cool Hack of the Year, and I nominate Paul
du
> Bois's one as the winner for 2004.  Do I hear any second...?

Thank you :-)

I am busy writing it up as a recipe.  I think I have a pleasing way for
it to be portable, even.  Unfortunately, that removes some of the evil.
p

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread [EMAIL PROTECTED]

Grant Edwards wrote:
> On 2004-12-31, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> >> When I copy code from a source file into a Google Groups
> >> message, the indentation is messed up, making my Python code
> >> illegal and all my code ugly. Are there tricks to avoid this?
> >
> > Try putting a # at the start of every line. Everyone should
> > understand what you mean (and you can always tell them to remove
> > the #'s once they copy the listing).
> >
> > #import gmpy
> > #i = 7
> > #while i<10:
>
> I always rather liked line numbers (a-la 'can -n').  That also
> makes discussion of the code easier:
>
>  1import gmpy
>  2i = 7
>  3while i<10:
>  4# conjecture 1
>  5
>  6 if ((i % 3)>0) and ((i % 5)>0):
>  7 f = gmpy.fib(i)
>  8 ip = gmpy.is_prime(i)
>  9 fm = f % i
> 10 if (fm==(i-1)) and (ip==0):
> 11 print "fib %5d: %5d (mod %5d)" %
(i,fm,i),
> 12 print gmpy.is_prime(i)
> 13 i += 2
> 14
> 15"""
> 16Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
> 17   then i is prime
> 18
> 19run #1 print all fib(i) == i-1 (mod i) that are composite
> 20
> 21fib  5777:  5776 (mod  5777) 0 <-- counter example
> 22fib 10877: 10876 (mod 10877) 0 <-- counter example
> 23fib 17261: 17260 (mod 17261) 0
> 24fib 75077: 75076 (mod 75077) 0 <-- counter example
> 25fib 80189: 80188 (mod 80189) 0
> 26"""
>
> Not sure what Google Groups does to it...

It wrapped lines 16 and 19. But "show original" restores it.

>
> --
> Grant Edwards   grante Yow!  Now I
understand the
>   at   meaning of "THE
MOD SQUAD"!
>visi.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread It's me

"John Machin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Andrew Dalke wrote:
> > "It's me" wrote:
> > > Here's a NDFA for your text:
> > >
> > >b  0 1-9 a-Z ,  . +  -   '   " \n
> > > S0: S0 E   E  S1  E E E S3 E S2  E
> > > S1: T1 E   E  S1  E E E  E  E  E T1
> > > S2: S2 E   E  S2  E E E  E  E T2  E
> > > S3: T3 E   E  S3  E E E  E  E  E T3
> >
> > Now if I only had an NDFA for parsing that syntax...
>
> Parsing your sentence as written ("if I only had"): If you were the
> sole keeper of the secret??
>
> Parsing it as intended ("if only I had"), and ignoring the smiley:
> Looks like a fairly straight-forward state-transition table to me.

Exactly.

> The
> column headings are not aligned properly in the message, b means blank,
> a-Z is bletchworthy, but the da Vinci code it ain't.
>
> If only we had an NDFA (whatever that is) for guessing what acronyms
> mean ...
>

I believe  (I am not a computer science major):

NDFA = non-deterministic finite automata

and:

S: state
T: terminal
E: error

So, S1 means State #1..T1 means Terminal #1, so forth

You are correct that parsing that table is not hard.

a) Set up a stack and place the buffer onto the stack, start with S0
b) For each character that comes from the stack, looking up the next state
for that token
c) If it's not a T or E state, jump to that state
d) If it's a T or E state, finish


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what would you like to see in a 2nd edition Nutshell?

2004-12-31 Thread Jay Parlar
Jumping in a bit late here, but I'd personally REALLY like to see 
something about PEP 246, and more specifically, what Phillip Eby has 
done about it with the PyProtocols package.

Especially with all this static typing talk going on these days, a good 
set of documentation (with lots of useful examples) on interfaces and 
adaption would probably be eye-opening to a lot of people.

It took a lot of experimenting to figure out the PyProtocols package, 
and to just get my head around the usefulness/point of PEP 246, but now 
that I have, wow, I don't know how I lived without it.

Jay P.

smime.p7s
Description: S/MIME cryptographic signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-31 Thread Scott David Daniels
Roel Schroeven wrote:
Rocco Moretti wrote:
So to summarize:
Commas define tuples, except when they don't, and parentheses are only 
required when they are necessary.
I hope that clears up any confusion.
You have my vote for QOTW.
+1 as well
By the way, since we seem to be commenting on sigs in this thread,
"Codito ergo sum"
brings to mind one I love:
"Cogito ergo spud!"  -- I think, therefore, yam!
(a U.S. Thanksgiving day coinage).
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQT installation

2004-12-31 Thread Brian
For those curious about Trolltech's stance on Windows, here's what
Trolltech's "License FAQ - Open Source Edition" (
http://www.trolltech.com/developer/faqs/license_gpl.html ) has to say:

" Why is there no Open Source (GNU GPL) version of Qt on Windows ?

We have regrettably not found a way of making GPL versions for Windows
available without risking the very business model we depend upon to be
able to further develop and support Qt.

Please note that if you make the source code for your project available
and your license allows it, any holder of a commercial Qt Windows
license can create binaries for your project. "

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Simo Melenius
Ian Bicking <[EMAIL PROTECTED]> writes:

> But I do think there's other ways to approach this.  Function
> expressions could get really out of hand, IMHO, and could easily lead
> to twenty-line "expressions".  That's aesthetically incompatible with
> Python source, IMHO.

You can already write unaesthetic hundred-line Python functions, if
you want to. Python's syntax doesn't yet impose a restriction on the
number of sequential statements :-) It sounds artificial to impose
such restrictions on these hypothetical "inline blocks", even if by
only allowing them to be plain expressions.

IMHO, the most pythonic way to write an "inline-block" is by reusing
existing keywords, using Python-like start-of-blocks and ending it by
indentation rules:

map (def x:
 if foo (x):
 return baz_1 (x)
 elif bar (x):
 return baz_2 (x)
 else:
 global hab
 hab.append (x)
 return baz_3 (hab),
 [1,2,3,4,5,6])

and for one-liners:

map (def x: return x**2, [1,2,3,4,5,6])

As a side-effect, we also

- got rid of the "lambda" keyword;

- strenghtened the semantics of "def": a "def" already defines a
  function so it's only logical to use it to define anonymous
  functions, too;

- unified the semantics: function is always a function, and functions
  return values by using "return". When learning Python, I learned the
  hard way that "lambda"s are expressions, not functions. I'd pay the
  burden of writing "return" more often in exchange for better
  consistency.


my two cents,
br,
S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Steve Holden
Cameron Laird wrote:
In article <[EMAIL PROTECTED]>,
Christopher Koppler  <[EMAIL PROTECTED]> wrote:
.
.
.
Manager culture is still very much mired in rituals that may in one form
or another go back to hunter-gatherer days (or maybe even further); that
'the industry choice' is more often than not something backed by a *major*
company is part of a ritual complex based on relations to the alpha male.
Small companies ingratiate themselves with their perceived betters by
using their products, even when technically far superior products would be
available. When the 'market leader' produces a new toy, everyone who wants
to be in his favor must use it _and_ also damn the toys available from any
of those competing for leadership, viz. the ongoing state of cold war
between Sun and MS and their respective worshipers. Toys that have not
been sanctioned by the leader, or that are, even worse, de facto unknown
to him, are met with ignorance, scorn, or even repression.
[snip]
For Python a Big Thing would happen if some Major Vendor
embraced it as its Official Language(tm). Python language
itself could turn into a smoking crock the very next day, but
everybody who doesn't live under the rock would still be 
writing in it.
The moral is, of course, that either the Python community's alpha geeks
need to get access to controlling interest in a *major* company (or to
become successful enough with their own companies to register on the
current *major* companies radar as potential competition) or as you
say, Python needs to be embraced like Linux was. That's the way to win the
hearts of software companies' managers.
.
.
.
I like repeating the description which emphasizes culture
and phenotype over the rationality of business schools.
Let me add a cautionary note, though:  Big Companies, 
including Oracle, Software AG, IBM, Cisco, and so on, have
adopted Tcl over and over.  All of them still rely on Tcl
for crucial products.  All of them also have employees who
sincerely wonder, "Tcl?  Isn't that dead?"

I offer this as a counter-example to the belief that Adop-
tion by a heavyweight necessarily results in widespread
acceptance.
Indeed. This is. of course, because they adopt the technology to achieve 
their business goals, and couldn't make money (using their traditional 
business models) by promoting the technologies they themselves rely on.

Would anyone undertake to give a "Hidden Technologies" talk at PyCon, 
outlining how this phenomenon operates against the adoption of 
technologies that the big boys effectively keep to themselves by keeping 
quiet about? Google's use of Python , while not a closely-kept a secret 
as Oracle's use of Tcl, certainly isn;t as well-known as it deserves to be.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


PyCon submission about to close

2004-12-31 Thread Steve Holden
Just a quick reminder for the laggards among us that you now have 
approximately SEVEN HOURS in which to submit your proposals for a talk 
at PyCon.

Thanks to all who have already taken the trouble to do so, and to the 
rest of you: GET ON WITH IT!

happy-new-year-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Adam DePrince
On Fri, 2004-12-31 at 01:53, Steven Bethard wrote:
> I thought it might be useful to put the recent lambda threads into 
> perspective a bit.  I was wondering what lambda gets used for in "real" 
> code, so I grepped my Python Lib directory.  Here are some of the ones I 
> looked, classified by how I would rewrite them (if I could):
> 


> So, those are my thoughts on how lambdas are "really" used.  If others 
> out there have real-life code that uses lambdas in interesting ways, 
> feel free to share them here!
> 

Lets not forget the "real reason" for lambda ... the elegance of
orthogonality.   Why treat functions differently than any other object? 

We can operate on every other class without having to involve the
namespace, why should functions be any different?  Wouldn't it to awful
if we had to write:

x = 3 * y ** 2 + 4 * y + 5 

as 

a = 3 
e = 2 
b = 4
c = 5
x = a * y ** e + b * y + c

Everybody understand that sometimes a number just isn't important enough
to assign to the name space.  And we all can understand that this
applies to other data types, for example:

print "The answer is", x

Unless internationalization was a concern, few people would write:

THE_ANSWER_IS = "The answer is"
print THE_ANSWER_IS, x

But when we consider functions, we suddenly change.  Understandably we
have a certain bias towards functions.  When programming, the most
commonly constructed object is the function.  We likely spend more time
crafting function objects than any other object.  Our reflex to
economize on the programming process focuses on the reduction in
function code creation time, hence the a focus on reuseabiity and a
plethora of ways to categorize our code to achieve this end.  

The notion that we would use a function exactly once is almost blasphemy
to such a perspective.  But it is true ... there are times when a
programmer will want to construct and use a function in exactly one
place for one singular purpose.  In my own code, this occurs most often
when the function is used as a parameters to another function.  

Examples of this are the cmp parameters to [].sort.  The function I
provide to cmp is only barely more important to preserve for posterity
than the value I might provide to the same functions "reverse"
parameter.

In sort, we must preserve the ability to create an anonymous function
simply because we can do so for every other object type, and functions
are not special enough to permit this special case.

Adam DePrince 


-- 
http://mail.python.org/mailman/listinfo/python-list


Quoting code [was: OT: spacing of code in Google Groups]

2004-12-31 Thread Steve Holden
[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
When I copy code from a source file into a Google Groups message,
the
indentation is messed up, making my Python code illegal and all my
code
ugly. Are there tricks to avoid this?
Try putting a # at the start of every line. Everyone should
understand what you mean (and you can always tell them to remove
the #'s once they copy the listing).
[...]

It would be helpful if submitted code were also copied to
  http://rafb.net/paste/
although I don;t know how long they archive the pastings. That's a site 
that gets used on the ##python IRC channel a lot, and it does make 
sharing very easy.

Having said which, there's still a lot going for just using spaces 
instead of tabs.

though-i-don't-know-what-ggogle-does-to-that-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread Adam DePrince
On Fri, 2004-12-31 at 13:03, [EMAIL PROTECTED] wrote:
> When I copy code from a source file into a Google Groups message, the
> indentation is messed up, making my Python code illegal and all my code
> ugly. Are there tricks to avoid this?

Subscribe to the [email protected] mailing list.  Take a look at
http://python.org/community/lists.html The news group and this list are
mirrors of each other.   Of course, the benefit this provides depends on
which mail client you use.


Adam DePrince 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Steven Bethard
Simo Melenius wrote:
map (def x:
 if foo (x):
 return baz_1 (x)
 elif bar (x):
 return baz_2 (x)
 else:
 global hab
 hab.append (x)
 return baz_3 (hab),
 [1,2,3,4,5,6])
I think this would probably have to be written as:
map (def x:
 if foo(x):
 return baz_1(x)
 elif bar(x):
 return baz_2(x)
 else:
 global hab
 hab.append(x)
 return baz_3(hab)
 , [1,2,3,4,5,6])
or:
map (def x:
 if foo(x):
 return baz_1(x)
 elif bar(x):
 return baz_2(x)
 else:
 global hab
 hab.append(x)
 return baz_3(hab)
 ,
 [1,2,3,4,5,6])
Note the placement of the comma.  As it is,
return baz_3(hab),
returns the tuple containing the result of calling baz_3(hab):
py> def f(x):
... return float(x),
...
py> f(1)
(1.0,)
It's not horrible to have to put the comma on the next line, but it 
isn't as pretty as your version that doesn't.  Unfortunately, I don't 
think anyone's gonna want to revise the return statement syntax just to 
introduce anonymous functions.

Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Mike Meyer
[EMAIL PROTECTED] (Cameron Laird) writes:

> For a not-too-different variety of safety, I like Eiffel.  Again,
> Eiffel compilers are available nearly, but not entirely, everywhere.

Eiffel compilers tend to generate C code, and hence work on anything
with a C compiler. The question then becomes how do you get to the
parts of your platform that you need to get work done.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Adam DePrince wrote:
Lets not forget the "real reason" for lambda ... the elegance of
orthogonality.   Why treat functions differently than any other object? 

We can operate on every other class without having to involve the
namespace, why should functions be any different?
Yup.  I think in most of the examples that I didn't know how to rewrite, 
this was basically the issue.  On the other hand, I do think that 
lambdas get overused, as indicated by the number of examples I *was* 
able to rewrite.[1]

Still, I have to admit that in some cases (especially those involving 
reduce), I wish the coder had named the function -- it would have given 
me a little bit more documentation as to what the code was trying to do.

On the other hand, in other cases, like when a function is a keyword 
argument to another function (e.g. inspect.py's "def formatargspec..." 
example) using a def statement and naming the function would be redundant.

Steve
[1] Note that this isn't entirely fair to the examples, some of which 
were written before list comprehensions, generator expressions and 
itemgetter/attrgetter.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Hans Nowak
Adam DePrince wrote:
In sort, we must preserve the ability to create an anonymous function
simply because we can do so for every other object type, and functions
are not special enough to permit this special case.
Your reasoning makes sense... lambda enables you to create a function as 
part of an expression, just like other types can be part of an 
expression.  However, by that same reasoning, maybe classes aren't 
special enough either to warrant a special case.  Where's the keyword to 
create an anonymous class? :-)

--
Hans Nowak
http://zephyrfalcon.org/
--
http://mail.python.org/mailman/listinfo/python-list


Zope newsgroups? Need help with POSKeyError

2004-12-31 Thread Bob Horvath
I have a Zope/Plone combination that I have been having POSKeyErrors 
with for a while now.  Are there any newsgroups that deal with Zope?
--
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Steven Bethard
Hans Nowak wrote:
Adam DePrince wrote:
In sort, we must preserve the ability to create an anonymous function
simply because we can do so for every other object type, and functions
are not special enough to permit this special case.

Your reasoning makes sense... lambda enables you to create a function as 
part of an expression, just like other types can be part of an 
expression.  However, by that same reasoning, maybe classes aren't 
special enough either to warrant a special case.  Where's the keyword to 
create an anonymous class? :-)
Well, no keyword, but you can use the type function:
py> d = dict(c=type('C', (object,), dict(spam=42)),
...  d=type('D', (dict,), dict(badger=True)))
py> d['c'].spam
42
py> d['c']()
<__main__.C object at 0x063F2DD0>
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Simo Melenius
Steven Bethard <[EMAIL PROTECTED]> writes:

> Simo Melenius wrote:
> > map (def x:
> >  if foo (x):
> >  return baz_1 (x)
> >  elif bar (x):
> >  return baz_2 (x)
> >  else:
> >  global hab
> >  hab.append (x)
> >  return baz_3 (hab),
> >  [1,2,3,4,5,6])
> 
> I think this would probably have to be written as:
...
>   return baz_3(hab)
>   , [1,2,3,4,5,6])
> or:
...
>   return baz_3(hab)
>   ,
>   [1,2,3,4,5,6])
> 
> Note the placement of the comma.  As it is,
>  return baz_3(hab),
> returns the tuple containing the result of calling baz_3(hab):

That one didn't occur to me; creating a one-item tuple with (foo,) has
been odd enough for me: only few times I've seen also the parentheses
omitted.

I did ponder the unambiguousness of the last line, though. One could
suggest a new keyword like "end", but keyword bloat is bad.

(Of course, if we trade the "lambda" keyword for another, new keyword
we're not exactly _adding_ keywords... :))

> It's not horrible to have to put the comma on the next line, but it
> isn't as pretty as your version that doesn't.  Unfortunately, I don't
> think anyone's gonna want to revise the return statement syntax just
> to introduce anonymous functions.

There might not be a return statement: the anonymous function might
conditionally return earlier and have side-effects at the end of the
block (to implicitly return None). So the block-ending would need to
fit after any statement and be strictly unambiguous.


br,
S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Doug Holton
Steven Bethard wrote:
Simo Melenius wrote:
map (def x:
 if foo (x):
 return baz_1 (x)
 elif bar (x):
 return baz_2 (x)
 else:
 global hab
 hab.append (x)
 return baz_3 (hab),
 [1,2,3,4,5,6])

I think this would probably have to be written as:
Right the comma plus other things make this difficult for a parser to 
handle correctly.  Other people have already come up with working solutions.

We have a special way to pass a multiline closure as a parameter to a 
function.  Put it outside the parameter list.

First, the single-line way using curly braces:
newlist = map({x as int | return x*x*x}, [1,2,3,4,5,6])
Then the multi-line way.  I had to add an overload of map to support 
reversing the order of parameters (list first, then the closure):

newlist = map([1,2,3,4,5,6]) def (x as int):
 return x*x*x
for item in newlist:
 print item
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Paul L. Du Bois
Alex Martelli wrote:
> We should have an Evilly Cool Hack of the Year, and I nominate
> Paul Du Bois's one as the winner for 2004.  Do I hear any second...?

Oh bother, I just realized I sent my first reply using a good email
address.  Hope that cancel goes through quickly.

Anyway, thank you!  I've submitted it as a recipe.  It includes a
less-evil portable version, which might be improved further if PEP 288
ever comes through.

p

The recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/361452

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zope newsgroups? Need help with POSKeyError

2004-12-31 Thread richard
Bob Horvath wrote:
> I have a Zope/Plone combination that I have been having POSKeyErrors
> with for a while now.  Are there any newsgroups that deal with Zope?

No, but there is a mailing list - see zope.org

Also, try google searching for POSKeyError.


Richard

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Steven Bethard
Paul Rubin wrote:
[EMAIL PROTECTED] (Alex Martelli) writes:
We should have an Evilly Cool Hack of the Year, and I nominate Paul du
Bois's one as the winner for 2004.  Do I hear any second...?
The year's not over yet :).
Ok, now that we're past 0:00:00 UTC, I'll second that nomination! ;)
Steve
P.S. Happy New Year all!
--
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote:
   ...
> > Your reasoning makes sense... lambda enables you to create a function as
> > part of an expression, just like other types can be part of an 
> > expression.  However, by that same reasoning, maybe classes aren't 
> > special enough either to warrant a special case.  Where's the keyword to
> > create an anonymous class? :-)
> 
> Well, no keyword, but you can use the type function:
> 
> py> d = dict(c=type('C', (object,), dict(spam=42)),
> ...  d=type('D', (dict,), dict(badger=True)))
> py> d['c'].spam
> 42
> py> d['c']()
> <__main__.C object at 0x063F2DD0>

Well then, just call new.function to similarly create functions as part
of an expression, hm?  Passing the bytecode in as a string isn't
incredibly legible, OK, but, we've seen worse...;-)


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Reinhold Birkenfeld
Adam DePrince wrote:

>> So, those are my thoughts on how lambdas are "really" used.  If others 
>> out there have real-life code that uses lambdas in interesting ways, 
>> feel free to share them here!
>> 
> 
> Lets not forget the "real reason" for lambda ...

I really hoped you would point out the _real_ reason for lambda...

> the elegance of orthogonality.

... but you didn't.


Everyone knows that lambda is there to help in one-liner contests and
code obfuscation.

Lambda is one of Python's very few instruments that assist in writing
code reaching Perl's unreadability, and as such it should be valued highly!



Reinhold
-- 
http://mail.python.org/mailman/listinfo/python-list


exposing C array to python namespace: NumPy and array module.

2004-12-31 Thread Bo Peng
Dear list,
I am writing a Python extension module that needs a way to expose pieces 
of a big C array to python. Currently, I am using NumPy like the following:

 PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE, 
char*buf);

Users will get a Numeric Array object and can change its values (and 
actually change the underlying C array).

This works fine. However, when I deliver my module, I find NumPy is 
unnecessarily large for this simple task. As a matter of fact, I had to 
 build from source NumPy, ATLAS etc on Solaris, Linux, Mac and if a 
user would like to use my module, he has to do the same thing!

Python's array module is built-in, easy to use, but *without* a 
FromLenAndData function! Even the buffer interface provides only 'get 
buffer' but no 'set buffer' functions. Could anyone tell me how I can 
create an array object from existing data? Some vague ideas might be 
used: 1. PyCObject (I do not really understand the manual), 2. copy and 
modify arraymodule.c to my project (doable at all? License issue?) 3. 
Create an array object and hack it. (no api to do this.)

I would strongly suggest an arraymodule.h with Array_FromLenAndData.
Many thanks in advance.
Bo
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread Peter Hansen
Grant Edwards wrote:
I always rather liked line numbers (a-la 'can -n').  That also
makes discussion of the code easier:
That, unfortunately, is somewhat harder to remove without
using a regular expression...  leading hash marks # is
pretty simple to remove with almost any editor.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread Freddie
Reinhold Birkenfeld wrote:
Freddie wrote:
Happy new year! Since I have run out of alcohol, I'll ask a question that I 
haven't really worked out an answer for yet. Is there an elegant way to turn 
something like:

> moo cow "farmer john" -zug
into:
['moo', 'cow', 'farmer john'], ['zug']
I'm trying to parse a search string so I can use it for SQL WHERE constraints, 
preferably without horrifying regular expressions. Uhh yeah.

The shlex approach, finished:
searchstring = 'moo cow "farmer john" -zug'
lexer = shlex.shlex(searchstring)
lexer.wordchars += '-'
poslist, neglist = [], []
while 1:
token = lexer.get_token()
# token is '' on eof
if not token: break
# remove quotes
if token[0] in '"\'':
token = token[1:-1]
# select in which list to put it
if token[0] == '-':
neglist.append(token[1:])
else:
poslist.append(token)
regards,
Reinhold
Thanks for this, though there was one issue:
>>> lexer = shlex.shlex('moo cow +"farmer john" -dog')
>>> lexer.wordchars += '-+'
>>> while 1:
... tok = lexer.get_token()
... if not tok: break
... print tok
...
moo
cow
+"farmer
john"
-dog
The '+"farmer john"' part would be turned into two seperate words, '+"farmer' 
and 'john"'. I ended up using shlex.split() (which the docs say is new in 
Python 2.3), which gives me the desired result. Thanks for the help from 
yourself and M.E.Farmer :)

Freddie
>>> shlex.split('moo cow +"farmer john" -"evil dog"')
['moo', 'cow', '+farmer john', '-evil dog']
>>> shlex.split('moo cow +"farmer john" -"evil dog" +elephant')
['moo', 'cow', '+farmer john', '-evil dog', '+elephant']
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread M.E.Farmer

py>b = shlex.shlex(a)
py>while 1:
... tok = b.get_token()
... if not tok: break
... print tok
...
moo
cow
+
"farmer john"
-
dog

Just wanted to share this just in case it might be relevant .
It seems if we don't add +- to wordchars then we get a different split
on "farmer john".
M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pygame + py2exe = bad exe. why?

2004-12-31 Thread Erik Bethke
M.E.Farmer wrote:
> Hello Erik,
> Have you ever seen pygame2exe.py?
> It is a py2exe script for pygame.

Hello M.E. Farmer,

Thank you for your response.  I looked into it and I discovered this
speedbump:

http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/2244073

"pygame-users
Re: [pygame] Pygame2Exe problems
by Zak Arntson other posts by this author
Dec 7 2004 8:38PM messages near this date Re: [pygame] Pygame2Exe
problems | Re: [pygame] Pygame2Exe problems

Well heck, this means that the pygame2exe.py program needs to be
updated. If I can get it working tonight, I'll post my results. I'm
going to be studying, though, so I can't promise anything. (It may be
quicker for me to just put Python and Pygame onto the CD).


On Tue, 7 Dec 2004 13:01:37 -0700, Tom Flanagan <[EMAIL PROTECTED]>
wrote:
>  Hi, the --console and --force arguments are depreciated in newer
>  py2exe versions.
>
>  they are now part of the setup() call.scroll down a bit on
>  http://starship.python.net/crew/theller/py2exe/ and it describes the
>  new usage.
>
>  should look something like this:
>
>  # setup.py
>  from distutils.core import setup
>  import py2exe
>
>  setup(console=["myscript.py"])
>  
>  #
>  python setup.py py2exe
>  
>  -Knio

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More baby squeaking - iterators in a class

2004-12-31 Thread Terry Reedy

"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Terry Reedy wrote:
>>will. Try ip=iter(p) followed by ip.next and ip.next() instead.

> Does that mean if you dont't call iter(() on your instance or have a
> next() method you can't do this:

> p=R3('eggs')
> for i in p:
>print i

Ignoring the older iteration method based on __getitem__, which I recommend 
you do ignore, yes, you cannot do that.

> I am asking because I want to fully understand what makes an
> *iterator*.

An iterator is an object with an __iter__ method that returns 'self' and a 
parameterless .next() method that on each call either returns an object or 
raises StopIteration.

An iterable is an object with an __iter__ method that returns an iterator.

A generator function (one containing yield in the code body), when called, 
returns a generator, which is a particular type of iterator.   So, a class 
with .__iter__ written as a generator function has iterable instances.

I can think of three reasons to go this latter route:
1. Writing a generator function may be easier that writing a standard 
function for .next.
2. The resulting iteration may be faster.
3. Iterating with a separate generator allows iteration without  disturbing 
the data of the instance (ie, non destructively).   This means that one can 
iterate more than once, even more than once at the same time.  Consider 
'multiplying' a sequence by itself:

  (i,j) for i in iterable for j in iterable

iter(iterable) is called once and then once again for each item yielded by 
the first call.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Bengt Richter
On 01 Jan 2005 00:56:30 +0200, Simo Melenius <[EMAIL PROTECTED]> wrote:

>Steven Bethard <[EMAIL PROTECTED]> writes:
>
>> Simo Melenius wrote:
>> > map (def x:
>> >  if foo (x):
>> >  return baz_1 (x)
>> >  elif bar (x):
>> >  return baz_2 (x)
>> >  else:
>> >  global hab
>> >  hab.append (x)
>> >  return baz_3 (hab),
>> >  [1,2,3,4,5,6])
>> 
>> I think this would probably have to be written as:
>...
>>   return baz_3(hab)
>>   , [1,2,3,4,5,6])
>> or:
>...
>>   return baz_3(hab)
>>   ,
>>   [1,2,3,4,5,6])
>> 
>> Note the placement of the comma.  As it is,
>>  return baz_3(hab),
>> returns the tuple containing the result of calling baz_3(hab):
>
>That one didn't occur to me; creating a one-item tuple with (foo,) has
>been odd enough for me: only few times I've seen also the parentheses
>omitted.
>
>I did ponder the unambiguousness of the last line, though. One could
>suggest a new keyword like "end", but keyword bloat is bad.
ISTM you don't need "end" -- just put the def expression in parens,
and let the closing paren end it, e.g.:

 map((def x:
  if foo (x):
  return baz_1 (x)
  elif bar (x):
  return baz_2 (x)
  else:
  global hab
  hab.append (x)
  return baz_3 (hab)), [1,2,3,4,5,6])

>
>(Of course, if we trade the "lambda" keyword for another, new keyword
>we're not exactly _adding_ keywords... :))
>
>> It's not horrible to have to put the comma on the next line, but it
>> isn't as pretty as your version that doesn't.  Unfortunately, I don't
>> think anyone's gonna want to revise the return statement syntax just
>> to introduce anonymous functions.
>
>There might not be a return statement: the anonymous function might
>conditionally return earlier and have side-effects at the end of the
>block (to implicitly return None). So the block-ending would need to
>fit after any statement and be strictly unambiguous.
Just use parens as necessary or when in doubt ;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More baby squeaking - iterators in a class

2004-12-31 Thread M.E.Farmer
Terry ,
Thank you for the explanation . That is much clearer now, I have played
a bit with generators but have never tried to create a custom iterator.
I am just now getting into the internals part of python objects... this
langauage is still amazing to me!
The reason I asked the question was because I tried that code I posted
and it worked fine in python2.2.3 ?

>Ignoring the older iteration method based on __getitem__, which I
recommend
>you do ignore, yes, you cannot do that.

py>class R3:
...def __init__(self, d):
...   self.d=d
...   self.i=len(d)
...def __iter__(self):
...   d,i = self.d, self.i
...   while i>0:
...   i-=1
...   yield d[i]
...
py>a = R3('qwerty')
py>dir(a)
['__doc__', '__init__', '__iter__', '__module__', 'd', 'i']
py>for i in a:
... print i
...
y
t
r
e
w
q
Ok I don't see __getitem__  anywhere in this object.
Still scratchin my head? Why does this work?
M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pygame + py2exe = bad exe. why?

2004-12-31 Thread M.E.Farmer

Erik  Bethke wrote:
> >  # setup.py
> >  from distutils.core import setup
> >  import py2exe
> >
> >  setup(console=["myscript.py"])
> >
> >  #
> >  python setup.py py2exe
> >
> >  -Knio

Erik glad to see you were able to track it down.
Have you been succesful in making the changes they mentioned?
M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Terry Reedy

"Adam DePrince" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> In sort, we must preserve the ability to create an anonymous function
> simply because we can do so for every other object type, and functions
> are not special enough to permit this special case.

Please show me how to create an anonymous type, module, or class, 
especially with an expression.  Number, sequences, and dicts have easily 
printable values.  Functions, like classes and module do not*, so 
definition names act as a standin and as a pointer to the source code that 
produced the object.  If functions are not special relative to classes and 
modules, which is the grouping they belong with, then we should get rid of 
lambda ;-)

*Now that memory is 'cheap', someone recently proposed that code objects 
(and hence functions) get .source attribute.  Maybe, someday...

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Jp Calderone
On Fri, 31 Dec 2004 22:09:49 -0500, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Adam DePrince" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > In sort, we must preserve the ability to create an anonymous function
> > simply because we can do so for every other object type, and functions
> > are not special enough to permit this special case.
> 
> Please show me how to create an anonymous type, module, or class, 
> especially with an expression.  Number, sequences, and dicts have easily 
> printable values.  Functions, like classes and module do not*, so 
> definition names act as a standin and as a pointer to the source code that 
> produced the object.  If functions are not special relative to classes and 
> modules, which is the grouping they belong with, then we should get rid of 
> lambda ;-)

>>> print type('', (object,), {'foo': lambda self: 'spam'})().foo()
spam

  Jp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread M.E.Farmer
Grant Edwards wrote:
>Not sure what Google Groups does to it...
The usual... it mangles it.
I don't get it, Google uses Python too, they know it is whitespace
signifigant.
I made a complaint several weeks ago to Google support ,
asking them too quit stripping leading whitespace,
and the sent me a reply saying they appreciated my feedback.
Maybe they  just need more feedback :)
M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Paul Rubin
Christopher Koppler <[EMAIL PROTECTED]> writes:
> >> 2. "plausible but there are sound technical reasons to be wary"
> > 
> > A security-critical financial application.
> 
> Why, specifically? Would you need to eval user input?

Static typing, checked exceptions, etc.
> 
> I haven't used those either (well, I looked at some, but I generally
> feel better at home in Emacs or even Idle than some glitzy IDE), but
> I find Python's debugging facilities completely sufficient,
> especially since I nearly never use them ;-) The interactive
> environment and unit testing are just great for whatever I've needed
> so far. But then I haven't used Python in a really *large* project
> yet, either.

I think it's partly a matter of development style.  I like debuggers
where some people prefer print statements.  IDLE's debugging features
were very crude, and IDLE locked up all the time or left stray threads
around when I used it.

There's lots of times when I have a cool programming idea, and find
when I sit down at the computer that I can implement the main points
of the idea and get a neat demo running rather quickly.  That creates
a very happy, liberating feeling, plus gives me something to show off
to friends or co-workers.  But turning it into a finished product with
no rough edges is an order of magnitude more work.  It seems to me
that IDLE and a lot of the rest of Python are examples of someone
having a cool idea and writing a demo, then releasing it with a lot of
missing components and rough edges, without realizing that it can't
reasonably be called complete without a lot more work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Of closures and expressing anonymous functions [Was: Re: Securing a future for anonymous functions in Python]

2004-12-31 Thread Terry Reedy

"Simo Melenius" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> [EMAIL PROTECTED] (Bengt Richter) writes:
> Which brings me to the point where I'd welcome more flexibility in
> writing to variables outside the local scope.

This idea was discussed extensively on PyDev perhaps 2 years ago.  (You can 
check the archived summaries if interested enough ;-)  As I remember, there 
was no consensus either on the desireability of such a mechanism or on the 
syntax (several were proposed).

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Any Python XML Data Binding Utilities Avaiable?

2004-12-31 Thread SeSe
Hi, every one, happy new year!
I am working on XML with Python. I wonder if there is any XML Schema<-> 
Python Object mapping tools so that we can convert one to another.
Thanks.

-SeSe
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread JanC
Steve Holden schreef:

> Would anyone undertake to give a "Hidden Technologies" talk at PyCon, 
> outlining how this phenomenon operates against the adoption of 
> technologies that the big boys effectively keep to themselves by
> keeping quiet about? Google's use of Python , while not a closely-kept
> a secret as Oracle's use of Tcl, certainly isn;t as well-known as it
> deserves to be. 

And since 2004-10-14, Corel uses Python too...  ;-)

They bought JASC Software last year, who use Python as a scripting 
language in their PaintShop Pro products.


-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread M.E.Farmer
No one pointed these out so here goes:
Python's list
http://www.python.org/Quotes.html
Disney animation
http://python.oreilly.com/news/disney_0201.html
Disney Panda3d
http://www.python.org/pycon/dc2004/papers/29/

There are several other companies using Python for game logic and
scripting, I am drawing a blank right now.

M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2004-12-31 Thread JanC
Adam DePrince schreef:

> On Fri, 2004-12-31 at 13:03, [EMAIL PROTECTED] wrote:
>> When I copy code from a source file into a Google Groups message, the
>> indentation is messed up, making my Python code illegal and all my code
>> ugly. Are there tricks to avoid this?
> 
> Subscribe to the [email protected] mailing list.  Take a look at
> http://python.org/community/lists.html The news group and this list are
> mirrors of each other.   Of course, the benefit this provides depends on
> which mail client you use.

I don't know if gmane keeps formating of messages intact when posting?
That could be an alternative too...

Or just use one of the free news servers, some of them even allow 
connections on port 80.  ;-)

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Lambda as declarative idiom (was RE: what is lambda used for in real code?)

2004-12-31 Thread Robert Brewer
Steven Bethard wrote:
> * Rewritable with existing functions
> Mainly these are examples of code that can benefit from using the
> functions available in the operator module, especially 
> operator.itemgetter and operator.attrgetter (available in 2.4)
> ...
> * Rewritable with list comprehensions/generator expressions
> Lambdas in map or filter expressions can often be replaced by an
> appropriate list comprehension or generator expression (in Python 2.3/2.4)
> ...
> So, those are my thoughts on how lambdas are "really" used.
> If others out there have real-life code that uses lambdas
> in interesting ways, feel free to share them here!

Admittedly, I use lambdas in a unique way; I turn them into SQL statements. But 
it points out what lambdas could become: a generic declarative idiom. You might 
notice that operator.add, for example, is not optimized for ints and strings 
like BINARY_ADD is (have a gander at ceval.c); instead, operator.add uses the 
"slow" PyNumber_Add. But your rewrites using operator.add are much faster than 
the equivalent lambdas, most likely due to the function-call overhead.

Wouldn't it be great if we could eval a lambda once, optimizing it as much as 
possible (using techniques like attrgetter, and possibly type annotations), and 
then let it run over large data sets? In the case of "lambda x: x + 3", we 
could use a type annotation to restrict the values of x to ints, and then take 
advantage of a compiler-side optimized int + int, evaluated once, rather than 
on each call. Lambdas would be much easier to optimize than full-blown 
functions (especially since most operations within lambdas do not produce 
side-effects).

I know; pipe dream. But that's what *I* use lambdas for (even if I have to 
transform Python bytecode into another language to do it at the moment ;).


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]


--
http://mail.python.org/mailman/listinfo/python-list


Weekly Python Patch/Bug Summary

2004-12-31 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  261 open ( +4) /  2718 closed ( +3) /  2979 total ( +7)
Bugs:  801 open ( -6) /  4733 closed (+16) /  5534 total (+10)
RFE :  165 open ( +2) /   139 closed ( +0) /   304 total ( +2)

New / Reopened Patches
__

Patch for bug 999042.  (2004-12-23)
   http://python.org/sf/1090482  opened by  Darek Suchojad

_AEModule.c patch  (2004-12-25)
   http://python.org/sf/1090958  opened by  has

py-compile DESTDIR support to compile in correct paths  (2004-12-27)
CLOSED http://python.org/sf/1091679  opened by  Thomas Vander Stichele

Refactoring Python/import.c  (2004-12-30)
   http://python.org/sf/1093253  opened by  Thomas Heller

socket leak in SocketServer  (2004-12-30)
   http://python.org/sf/1093468  opened by  Shannon -jj Behrens

sanity check for readline remove/replace  (2004-12-30)
   http://python.org/sf/1093585  opened by  DSM

miscellaneous doc typos  (2004-12-31)
CLOSED http://python.org/sf/1093896  opened by  DSM

Patches Closed
__

Avoid calling tp_compare with different types  (2004-07-22)
   http://python.org/sf/995939  closed by  arigo

py-compile DESTDIR support to compile in correct paths  (2004-12-27)
   http://python.org/sf/1091679  closed by  jafo

miscellaneous doc typos  (2004-12-31)
   http://python.org/sf/1093896  closed by  rhettinger

New / Reopened Bugs
___

presentation typo in lib: 6.21.4.2 How callbacks are called  (2004-12-23)
   http://python.org/sf/1090139  reopened by  jlgijsbers

input from numeric pad always dropped when numlock off  (2004-11-27)
   http://python.org/sf/1074333  reopened by  kbk

minor bug in what's new > decorators  (2004-12-26)
CLOSED http://python.org/sf/1091302  opened by  vincent wehren

A large block of commands after an "if" cannot be   (2003-03-28)
   http://python.org/sf/711268  reopened by  facundobatista

DESTROOTed frameworkinstall fails  (2004-12-26)
CLOSED http://python.org/sf/1091468  opened by  Jack Jansen

No need to fix  (2004-12-27)
CLOSED http://python.org/sf/1091634  opened by  Bertram Scharpf

garbage collector still documented as optional  (2004-12-27)
   http://python.org/sf/1091740  opened by  Gregory H. Ball

IDLE hangs due to subprocess  (2004-12-28)
   http://python.org/sf/1092225  opened by  ZACK

slice [0:] default is len-1 not len  (2004-12-28)
CLOSED http://python.org/sf/1092240  opened by  Robert Phillips

Memory leak in socket.py on Mac OS X 10.3  (2004-12-28)
   http://python.org/sf/1092502  opened by  bacchusrx

os.remove fails on win32 with read-only file  (2004-12-29)
   http://python.org/sf/1092701  opened by  Joshua Weage

Make Generators Pickle-able  (2004-12-29)
   http://python.org/sf/1092962  opened by  Jayson Vantuyl

distutils/tests not installed  (2004-12-30)
   http://python.org/sf/1093173  opened by  Armin Rigo

mapitags.PROP_TAG() doesn't account for new longs  (2004-12-30)
   http://python.org/sf/1093389  opened by  Joe Hildebrand

Bugs Closed
___

presentation typo in lib: 6.21.4.2 How callbacks are called  (2004-12-22)
   http://python.org/sf/1090139  closed by  rhettinger

Memory leaks?  (2004-10-16)
   http://python.org/sf/1048495  closed by  rhettinger

_bsddb segfault  (2004-07-15)
   http://python.org/sf/991754  closed by  dcjim

coercion results used dangerously  (2004-06-26)
   http://python.org/sf/980352  closed by  arigo

exec scoping problem  (2004-12-22)
   http://python.org/sf/1089978  closed by  arigo

_DummyThread() objects not freed from threading._active map  (2004-12-22)
   http://python.org/sf/1089632  closed by  bcannon

Mac Library Modules 1.1.1 Bad Info  (2004-12-14)
   http://python.org/sf/1085300  closed by  bcannon

minor bug in what's new > decorators  (2004-12-26)
   http://python.org/sf/1091302  closed by  montanaro

A large block of commands after an "if" cannot be   (2003-03-28)
   http://python.org/sf/711268  closed by  bcannon

Failed assert in stringobject.c  (2003-05-14)
   http://python.org/sf/737947  closed by  facundobatista

DESTROOTed frameworkinstall fails  (2004-12-26)
   http://python.org/sf/1091468  closed by  jackjansen

nturl2path.url2pathname() mishandles ///  (2002-12-07)
   http://python.org/sf/649961  closed by  mike_j_brown

No need to fix  (2004-12-27)
   http://python.org/sf/1091634  closed by  mwh

2.4a3: unhelpful error message from distutils  (2004-09-03)
   http://python.org/sf/1021756  closed by  effbot

BuildApplication includes many unneeded modules  (2004-12-01)
   http://python.org/sf/1076492  closed by  jackjansen

slice [0:] default is len-1 not len  (2004-12-28)
   http://python.org/sf/1092240  closed by  jlgijsbers

truncated gzip file triggers zlibmodule segfault  (2004-12-10)
   http://python.org/sf/1083110  closed by  akuchling

os.ttyname() accepts wrong arguments  (2004-12-07)
   http://

Re: OT: spacing of code in Google Groups

2004-12-31 Thread Dan Bishop
M.E.Farmer wrote:
> Grant Edwards wrote:
> >Not sure what Google Groups does to it...
> The usual... it mangles it.
> I don't get it, Google uses Python too, they know it is whitespace
> signifigant.

And for a long time, Google groups postings *were* whitespace
significant.  But the new interface broke it.

> I made a complaint several weeks ago to Google support,
> asking them too quit stripping leading whitespace,
> and the sent me a reply saying they appreciated my feedback.
> Maybe they  just need more feedback :)

I send them some earlier today.  So far, I've only received their
auto-reply.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Aahz
In article <[EMAIL PROTECTED]>,
Adam DePrince  <[EMAIL PROTECTED]> wrote:
>
>Unless internationalization was a concern, few people would write:
>
>THE_ANSWER_IS = "The answer is"
>print THE_ANSWER_IS, x

However, there's a moderately large (and growing!) set of people who
would argue that I18N is *always* a concern -- it's just that a lot of
people either don't know it yet or ignore it.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >