Amara XML Toolkit 0.9.1 changes

2004-12-31 Thread Uche Ogbuji
Forgot the changes in the original announcement:

* Fixed embarrassing misinterpretation of
  sax.handler.feature_namespace_prefixes
  Now Namespace prefixes work fine with or without PyXML installed
* Add saxtools.namespace_mixin utility class
* Clean up bindery.document_base name attributes
* Add bindery.element_base.xml_remove_child and .xml_index_on_parent--
methods for easier removal of children
* tenorsax was useless due to accidental late mangling before 0.9.0
release.  Fixed.
* Use tenorsax fully in Scimitar.
  Scimitar is now a complete ISO schematron implementation in about 500
lines
  of Python code (including the skeletons for code generation)

http://lists.fourthought.com/pipermail/4suite/2004-December/013143.html


-- 
Uche OgbujiFourthought, Inc.
http://uche.ogbuji.nethttp://4Suite.orghttp://fourthought.com
Use CSS to display XML - 
http://www.ibm.com/developerworks/edu/x-dw-x-xmlcss-i.html
Full XML Indexes with Gnosis - http://www.xml.com/pub/a/2004/12/08/py-xml.html
Be humble, not imperial (in design) - http://www.adtmag.com/article.asp?id=10286
UBL 1.0 - http://www-106.ibm.com/developerworks/xml/library/x-think28.html
Use Universal Feed Parser to tame RSS - 
http://www.ibm.com/developerworks/xml/library/x-tipufp.html
Default and error handling in XSLT lookup tables - 
http://www.ibm.com/developerworks/xml/library/x-tiplook.html
A survey of XML standards - 
http://www-106.ibm.com/developerworks/xml/library/x-stand4/
The State of Python-XML in 2004 - 
http://www.xml.com/pub/a/2004/10/13/py-xml.html

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: The Industry choice

2004-12-31 Thread Alan Gauld
On 30 Dec 2004 08:58:36 -0800, Sridhar  R
[EMAIL PROTECTED] wrote:
 What makes such companies to choose Java over dynamic, productive
 languages like Python?  Are there any viable, technical reasons for
 that?

Decisions are made by men in suits who read very expensive
business magazines, read technical reports by the like of
Gartner and Forester and get taken on expenses-paid trips by
company sales reps. My boss has never had his lunch paid 
for by a man selling Python...

Think about the PHB in Dilbert, if some guy in a sharp suit from
a big supplier says use Java, while Dilbert and the others say
Python what will he pick?

There are some valid technical reasons to do with performance and
security too, but frankly, they come a long way down the list...

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Paul Rubin
Sridhar  R [EMAIL PROTECTED] writes:
 What makes such companies to choose Java over dynamic, productive
 languages like Python?  Are there any viable, technical reasons for that?

I think you have to be more careful when you program in Python.  Java
is statically typed and can do all kinds of compile time checks that
catch errors which can crash your Python program after it's running.
The cure in Python involves very thorough testing, and it often means
more test-debug-edit cycles than you'd need with static typing.  It's
also possible to miss stuff--not just type errors, but uncaught
exceptions, errors due to misspelled variable names (Python lacks
declarations), and so forth.  Some Pythonistas respond with a blurb
about test-driven development, but really, the idea of programming in
HLL's instead of assembler is that the language is supposed to take
care of stuff so that you don't have to.  Java code is larger and
takes longer to write, but has a higher chance of working properly
once it compiles and passes basic tests.  (Of course you still have to
test it thoroughly, but you'll tend to hit fewer errors once you've
passed the initial and somewhat high hurdle of getting the code to
work at all).

Basically, highly-skilled programmers can be very productive with
Python, maybe more productive than they can be with Java.
Medium-skilled programmers, which is what the industry is full of, can
mess up very badly with a language like Python.  With Java, it's
harder to mess up too badly.

I'm involved in a development project for something that's security
critical and has to be reliable.  The implementation language hasn't
been chosen yet.  Python and Java are both possibilities.  I'm fine
with the idea of using Python for demos and prototypes.  For the
production system I think we may be better off using Java.
Reliability of the final product is more important than rapid
implementation.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Is there a better way of listing Windows shares other than us ing os.listdir

2004-12-31 Thread Doran_Dermot
Hi David,

Thanks for the bit of code on finding shares!  I'd been using something a
bit different (win32com.client stuff) but your code looks better. 

I've found that win32file.FindFilesIterator (suggested to me by another
person on this mailing list) allows the gui to remain responsive. Using the
same code to execute the os.listdir hangs the gui!

I've been using the wx.PostEvent and Python threading objects to implement
multi-threading. Works very well!  The wxPython demo illustrates the use of
wx.PostEvent and Python multi-threading extremely well.

Thanks again for your help!

Dermot.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
David Bolen
Sent: 30 December 2004 17:39
To: python-list@python.org
Subject: Re: Is there a better way of listing Windows shares other than
using os.listdir

[EMAIL PROTECTED] writes:

 I'm currently using os.listdir to obtain the contents of some slow
Windows
 shares.  I think I've seen another way of doing this using the win32
library
 but I can't find the example anymore.

Do you want the list of files on the shares or the list of shares
itself?  If the files, you can use something like FindFiles, but I
don't expect it to be that much faster just to obtain directory names
(likely the overhead is on the network).

If you just want a list of shares, you could use NetUseEnum, which
should be pretty speedy.

(FindFiles is wrapped by win32api, and NetUseEnum by win32net, both parts
 of the pywin32 package)

Here's a short example of displaying equivalent output to the net
use command:

  - - - - - - - - - - - - - - - - - - - - - - - - -
import win32net

status = {0 : 'Ok',
  1 : 'Paused',
  2 : 'Disconnected',
  3 : 'Network Error',
  4 : 'Connected',
  5 : 'Reconnected'}

resume = 0
while 1:
(results, total, resume) = win32net.NetUseEnum(None, 1, resume)
for use in results:
print '%-15s %-5s %s' % (status.get(use['status'], 'Unknown'),
 use['local'],
 use['remote'])
if not resume:
break
  - - - - - - - - - - - - - - - - - - - - - - - - -

Details on the the arguments to NetUseEnum can be found in MSDN (with
any pywin32 specifics in the pywin32 documentation).

 My main problem with using os.listdir is that it hangs my gui
application.
 The tread running the os.listdir appears to block all other threads when
 it calls this function.

Yes, for a GUI you need to keep your main GUI thread always responsive
(e.g., don't do any blocking operations).

There are a number of alternatives to handling a long processing task
in a GUI application, dependent on both the operation and toolkit in
use.  For wxPython, http://wiki.wxpython.org/index.cgi/LongRunningTasks
covers several of the options (and the theory behind them is generally
portable to other toolkits although implementation will change).

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


Re: Securing a future for anonymous functions in Python

2004-12-31 Thread Ian Bicking
John Roth wrote:
I appreciate some of the motivation, but merely avoiding giving 
something a name doesn't seem like a laudible goal.
Actually, it is a laudable goal. It's always easier to understand
something when it's right in front of your face than if it's
off somewhere else.
Naming the function doesn't move it far away.  It changes the order (you 
have to define it before you use it), and it introduces a name.

The one motivation I can see for function expressions is 
callback-oriented programming ...
Well, that's true, but that's a very global statement:
when you pass a function into another routine, it's
essentially a callback.
Sure, technically.  But I'm thinking of real use cases.  One I'm 
familiar with is things like map and filter.  These are generally better 
handled with list expressions (and MUCH more readable as such, IMHO). 
Another is control structures, ala Ruby or Smalltalk.  IMHO, we have all 
the control structures we need -- while, for, if.  Most novel control 
structures in Ruby or Smalltalk are just another take on iterators.  The 
exception being callbacks, and perhaps some other lazy evaluation 
situations (though outside of what I think of as callbacks, I can't 
think of any lazy evaluation situations off the top of my head).

So that's why I think callbacks are important; callbacks in the style of 
Twisted Deferred, GUI events, etc.

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.
Anything can get  out of hand; there's no way of legislating
good style without restricting the language so much that it
becomes unusable for anything really interesting. Even then
it doesn't work: see COBOL as a really good example of
good intentions gone seriously wrong.
OK, I should go further -- even a two-line expression (i.e., an 
expression that contains meaningful vertical whitespace) is 
aesthetically incompatible with Python source.  Which covers any 
anonymous function that is more powerful than lambda.  I'm not arguing 
that it can be abused, but more that it isn't any good even when it's 
not being abused.

Have you ever programmed in a language that does use
anonymous functions extensively like Smalltalk?
Yep, I've done a fair amount of Smalltalk and Scheme programming.  I 
don't expect Python to act like them.  I appreciate the motivation, but 
I don't think their solution is the right one for Python.

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


py2app on Mac OS X 10.3

2004-12-31 Thread Austin

Minimal setup.py example, run with:
% python setup.py py2app


from distutils.core import setup
import py2app
setup(
app = ['main.py'],
)

That is a sample code of wiki.
I have a file 'main.py' and several sub-folders.
After I execute 'pythonw setup.py py2exe', I see 2 folders, 'dist'  'build'
which is the same as py2exe.
I open the 'dist' folder and see a file 'main'. Then I double-click the
'main' and appeared the error message.
'IOError:[Errno 2] No such file or directory:
'/user/austin/Desktop/disk/main.app/Contents/Resources/log/eventlog.xml
I feel so wildered because 'main.app' should be a file not a folder.

I was wondering if some extra codes needed by setup.py
Could anyone give me an advice?
Thanks a lot.


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


Re: More baby squeaking - iterators in a class

2004-12-31 Thread Bulba!
On Thu, 30 Dec 2004 12:06:31 -0800, Scott David Daniels
[EMAIL PROTECTED] wrote:

Here's one way:  # (Make __iter__ an iterator)
Py class R1(object):
 def __init__(self, data):
 self.data = data
 self.i = len(data)
 def __iter__(self):
 while self.i  0:
 self.i -= 1
 yield self.data[self.i]

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 i0:
i-=1
yield d[i]

 p=R3('eggs')
 p.next()
Traceback (most recent call last):
  File interactive input, line 1, in ?
AttributeError: R3 instance has no attribute 'next'
 dir(p)
['__doc__', '__init__', '__iter__', '__module__', 'd', 'i']
 list(p)
['s', 'g', 'g', 'e']
 

I tried all the methods advised by you and other posters and they do
return an object with __iter__, but not with the next method.

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')
 o
generator object at 0x0120DF58
 dir(o)
['__class__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__iter__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', 'gi_frame',
'gi_running', 'next']
 o.next()
's'
 o.next()
'g'
 o.next()
'g'
 o.next()
'e'


The function returns 'generator object', as shown above, 
while p is a class instance:

 p
__main__.R3 instance at 0x0123CA58




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


Re: Speed ain't bad

2004-12-31 Thread Craig Ringer
On Fri, 2004-12-31 at 11:17, Jeremy Bowers wrote:

 I would point out a couple of other ideas, though you may be aware of
 them: Compressing all the files seperately, if they are small, may greatly
 reduce the final compression since similarities between the files can not
 be exploited.

True; however, it's my understanding that compressing individual files
also means that in the case of damage to the archive it is possible to
recover the files after the damaged file. This cannot be guaranteed when
the archive is compressed as a single stream.

--
Craig Ringer

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


Re: The Industry choice

2004-12-31 Thread Bulba!
On Thu, 30 Dec 2004 12:59:57 -0500, Steve Holden [EMAIL PROTECTED]
wrote:
 We either need time for folks to accept dynamic, scripting
 languages, or a lot of modern language programmers need to gang up
 against managers and stuff. :)

[...]
Right, what have the managers ever done for us?

I must have been slow last night (my usual state), so I 
didn't catch your joke.

Respectfully, I have to disagree: Terrific race, managers.
Terrific. ;-)



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


Re: copying classes?

2004-12-31 Thread harold fellermann
On 30.12.2004, at 01:24, It's me wrote:
I would not think that a generic deepcopy would work for all cases.   
An
object can be as simple as a number, for instance, but can also be as
complex as the universe.  I can't imagine anybody would know how to 
copy a
complex object otherthen the object itself.

I always think that a well designed object should have a copyme method.
:=)
take a look at the __setstate__ and __getstate__ documentation of copy
(e.g. pickle) -- with them you can customize the copying task. Anyway,
they work only on instance but not on class objects :(
- harold -
--
Military intelligence is a contradiction in terms.
-- Groucho Marx
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Peter Dembinski
Thomas Bartkus [EMAIL PROTECTED] writes:

[...]

  What makes such companies to choose Java over dynamic, productive
  languages like Python?  Are there any viable, technical reasons
  for that?

 Are there viable, technical reasons?  That would be doubtful.

 But

 There is a reason very important to major companies.  When you leave
 that company, there will be a *long* line of Java programmers
 waiting to take your place.

IMO learning Python is a matter of few days for Java programmer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2app on Mac OS X 10.3

2004-12-31 Thread Ronald Oussoren
On 31-dec-04, at 11:12, Austin wrote:

Minimal setup.py example, run with:
% python setup.py py2app

from distutils.core import setup
import py2app
setup(
app = ['main.py'],
)
That is a sample code of wiki.
I have a file 'main.py' and several sub-folders.
After I execute 'pythonw setup.py py2exe', I see 2 folders, 'dist'  
'build'
which is the same as py2exe.
I open the 'dist' folder and see a file 'main'. Then I double-click the
'main' and appeared the error message.
'IOError:[Errno 2] No such file or directory:
'/user/austin/Desktop/disk/main.app/Contents/Resources/log/eventlog.xml
I feel so wildered because 'main.app' should be a file not a folder.
It's an application bundle, which is a folder. All '.app'-s on OS X are 
folders, it is a neat way of bundling the application program and all 
data files it needs.

I was wondering if some extra codes needed by setup.py
Could anyone give me an advice?
What is 'eventlog.xml' supposed to be? If you're going to write to it, 
it is in the wrong location. If it is a datafile that is used by your 
application you should mention it in the setup.py script (the 
data_files argument).

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


Re: The Industry choice

2004-12-31 Thread Christopher Koppler
On Fri, 31 Dec 2004 02:13:27 +0100, Bulba! wrote:

 On 30 Dec 2004 08:58:36 -0800, Sridhar  R
 [EMAIL PROTECTED] wrote:
 
[snip]
 
What makes such companies to choose Java over dynamic, productive
languages like Python?  Are there any viable, technical reasons for
that?
 
 It's the $$$ of the big organization behind it and all the 
 inertia^H^H^H^H^H^H stability of it.
 
 Note all the fuss that was made when IBM has spent $1 
 billion on Linux, for instance (or so it was said). Managers
 paid attention to that (at least that was my impression).
 
 AFAIK, Linux didn't really change in technical sense
 just because IBM has embraced Linux, or at least not much.
 But to companies and manager the major point is:
 
 Big Blue has embraced it. 

[add a few grains of salt to the following...]
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.

-- 
Christopher

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


Re: The Industry choice

2004-12-31 Thread Christopher Koppler
On Fri, 31 Dec 2004 12:05:47 +0100, Peter Dembinski wrote:

 Thomas Bartkus [EMAIL PROTECTED] writes:
 
 [...]
 
  What makes such companies to choose Java over dynamic, productive
  languages like Python?  Are there any viable, technical reasons
  for that?

 Are there viable, technical reasons?  That would be doubtful.

 But

 There is a reason very important to major companies.  When you leave
 that company, there will be a *long* line of Java programmers
 waiting to take your place.
 
 IMO learning Python is a matter of few days for Java programmer.

True, but learning to *think* in Python takes a while longer. That static
straitjacket takes some time to loosen...

-- 
Christopher

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


Re: copying classes?

2004-12-31 Thread Alex Martelli
harold fellermann [EMAIL PROTECTED] wrote:
   ...
  I always think that a well designed object should have a copyme method.
  :=)

That would be __copy__ or __deepcopy__, but the __getstate__ /
__setstate__ approach is often preferable.

 take a look at the __setstate__ and __getstate__ documentation of copy
 (e.g. pickle) -- with them you can customize the copying task. Anyway,
 they work only on instance but not on class objects :(

They should, if you put them in the class of the class -- the metaclass.

 class mec(type):
...   def __copy__(cls):
... return mec('copyof'+cls.__name__, cls.__bases__,
dict(vars(cls)))
... 
 class foo:
...   __metaclass__ = mec
... 
 bar = copy.copy(foo)
 bar.__name__
'copyoffoo'
 


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


Re: The Industry choice

2004-12-31 Thread Paul Rubin
Christopher Koppler [EMAIL PROTECTED] writes:
 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.

It's not just a matter of attitude or politics.  Python is an
excellent choice for many projects.  For some other projects, it's
clearly unsuitable.  For yet other projects, it's a plausible choice
but there are sound technical reasons to be wary of it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about pure virtual methods?

2004-12-31 Thread Noam Raphael
Thanks for your suggestion, but it has several problems which the added 
class solves:

* This is a very long code just to write you must implement this 
method. Having a standard way to say that is better.
* You can instantiate the base class, which doesn't make sense.
* You must use testing to check whether a concrete class which you 
derived from the base class really implemented all the abstract methods. 
Testing is a good thing, but it seems to me that when the code specifies 
exactly what should happen, and it doesn't make sense for it not to 
happen, there's no point in having a separate test for it.

About the possibility of implementing only a subset of the interface: 
You are perfectly welcomed to implement any part of the interface as you 
like. Function which use only what you've implemented should work fine 
with your classes. But you can't claim your classes to be instances of 
the base class - as I see it, subclasses, even in Python, guarantee to 
behave like their base classes.

Have a good day,
Noam
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Christopher Koppler
On Fri, 31 Dec 2004 03:49:44 -0800, Paul Rubin wrote:

 Christopher Koppler [EMAIL PROTECTED] writes:
 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.
 
 It's not just a matter of attitude or politics.  Python is an
 excellent choice for many projects.  For some other projects, it's
 clearly unsuitable.  For yet other projects, it's a plausible choice
 but there are sound technical reasons to be wary of it.

IMO (and - indubitably limited - experience) in the many cases where it
*would* be an excellent choice, it *is* most often a matter of politics,
to have a project use, say C# or Java instead of Python (or Lisp for that
matter) as the main development language.

-- 
Christopher

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


Re: The Industry choice

2004-12-31 Thread Paul Rubin
Christopher Koppler [EMAIL PROTECTED] writes:
 IMO (and - indubitably limited - experience) in the many cases where it
 *would* be an excellent choice, it *is* most often a matter of politics,
 to have a project use, say C# or Java instead of Python (or Lisp for that
 matter) as the main development language.

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.  
-- 
http://mail.python.org/mailman/listinfo/python-list


ftplib strange behaviour

2004-12-31 Thread siggy2
Hi,
I'm using
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
on win32
I've noticed a strange (= not deterministic) behaviour of ftplib.py:
sometimes (not always) it fails (after a variable number of minutes
from 15 to 130) downloading a 150 MB BINARY file
(a big gzipped ascii file) with the traceback reported
below.
IMVHO this is not a timeout error because my script import
timeoutsocket.py (__version__ = $Revision: 1.1.22.1 $
__author__  = Timothy O'Malley [EMAIL PROTECTED])
to explicitly trap that...
and whenever a timeout occurs it is correctly reported and handled
(timeout set to 240 seconds)


Traceback (most recent call last):
File C:\mydir\myscript.py, line 77, in downloadFile
result = ftpObject.retrbinary('RETR '+name, f.write)
File C:\Python23\lib\ftplib.py, line 386, in retrbinary
return self.voidresp()
File C:\Python23\lib\ftplib.py, line 221, in voidresp
resp = self.getresp()
File C:\Python23\lib\ftplib.py, line 207, in getresp
resp = self.getmultiline()
File C:\Python23\lib\ftplib.py, line 193, in getmultiline
line = self.getline()
File C:\Python23\lib\ftplib.py, line 183, in getline
if not line: raise EOFError


In ftplib.py I read this comment:
[CUT]
# Internal: return one line from the server, stripping CRLF.
# Raise EOFError if the connection is closed
def getline(self):
[CUT]

May anyone explain me what is this?
Could this error be explained only as a ftp server problem?
TIA!
bye,
   PiErre

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


Re: The Industry choice

2004-12-31 Thread Christopher Koppler
On Fri, 31 Dec 2004 04:03:53 -0800, Paul Rubin wrote:

 Christopher Koppler [EMAIL PROTECTED] writes:
 IMO (and - indubitably limited - experience) in the many cases where it
 *would* be an excellent choice, it *is* most often a matter of politics,
 to have a project use, say C# or Java instead of Python (or Lisp for that
 matter) as the main development language.
 
 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.

Well, it *does* take some pointers from Python but it's still
much more like Java (and even C++) under the hood, AFAIK. I'll get to
know firsthand soon, though, as I'll have to acquaint myself fully with
C#'s benefits, pitfalls and whatnot for a new project I'm on that (for
definitely political reasons) will have it as the main development
language. I'd pity myself if it weren't temporary; Python withdrawal isn't
good for my health ;-)

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


Re: lies about OOP

2004-12-31 Thread TZOTZIOY
On Wed, 15 Dec 2004 17:37:08 -0500, rumours say that Peter Hansen
[EMAIL PROTECTED] might have written:

Martijn Faassen wrote:
 Peter Hansen wrote:
 Well, in any case, thanks for setting the record straight, Martjin.
 
 That of course also happens to me once every while. I can take care of 
 myself though -- Dijkstra however needs an advocate for the correct 
 spelling of his name in this earthly realm.

Then there's us Danes, with sen instead of son (as many people
think it ought to be).  And I can't even claim the wrong form
sounds noticably different, making any defense seem petty.

So this means that if Guido was Dane too we would program in Pythen.

The Zon of Pythen.  The Sen Of Dr Strangelove.  Nice.

Happy new year in advance every one, don't start drinking before you
drive home :)
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed ain't bad

2004-12-31 Thread Reinhold Birkenfeld
Craig Ringer wrote:
 On Fri, 2004-12-31 at 11:17, Jeremy Bowers wrote:
 
 I would point out a couple of other ideas, though you may be aware of
 them: Compressing all the files seperately, if they are small, may greatly
 reduce the final compression since similarities between the files can not
 be exploited.
 
 True; however, it's my understanding that compressing individual files
 also means that in the case of damage to the archive it is possible to
 recover the files after the damaged file. This cannot be guaranteed when
 the archive is compressed as a single stream.

With gzip, you can forget the entire rest of the stream; with bzip2,
there is a good chance that nothing more than one block (100-900k) is lost.

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


Re: The Industry choice

2004-12-31 Thread Bulba!
On 31 Dec 2004 03:49:44 -0800, Paul Rubin
http://[EMAIL PROTECTED] wrote:
It's not just a matter of attitude or politics.  Python is an
excellent choice for many projects.  For some other projects, it's
clearly unsuitable.  For yet other projects, it's a plausible choice
but there are sound technical reasons to be wary of it.

(being the usual me, I can't resist putting a stick into
a nest of pythons)

OK, so what projects and why would you consider 
Python:

1. clearly unsuitable 

2. plausible but there are sound technical reasons
to be wary

BTW, I don't think I agree with your statement
elsewhere about unit tests - if you write a prototype
(in any language), why bother with unit tests, and
if you write security-critical app, maybe the tests 
should be written anyway (again, whatever is the
language chosen for a project).




--
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 Peter Dembinski
Paul Rubin http://[EMAIL PROTECTED] writes:

[...]

 I'm involved in a development project for something that's security
 critical and has to be reliable.  The implementation language hasn't
 been chosen yet.  Python and Java are both possibilities.  I'm fine
 with the idea of using Python for demos and prototypes.  For the
 production system I think we may be better off using Java.
 Reliability of the final product is more important than rapid
 implementation.

If it has to be both reliable and secure, I suggest you used more
redundant language such as Ada 95.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed ain't bad

2004-12-31 Thread Bulba!
On Fri, 31 Dec 2004 13:19:44 +0100, Reinhold Birkenfeld
[EMAIL PROTECTED] wrote:

 True; however, it's my understanding that compressing individual files
 also means that in the case of damage to the archive it is possible to
 recover the files after the damaged file. This cannot be guaranteed when
 the archive is compressed as a single stream.

With gzip, you can forget the entire rest of the stream; with bzip2,
there is a good chance that nothing more than one block (100-900k) is lost.

I have actually written the version of that script with bzip2 but 
it was so horribly slow that I chose the zip version.






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


Re: Speed ain't bad

2004-12-31 Thread Bulba!
On Thu, 30 Dec 2004 22:17:10 -0500, Jeremy Bowers [EMAIL PROTECTED]
wrote:

I would point out a couple of other ideas, though you may be aware of
them: Compressing all the files seperately, if they are small, may greatly
reduce the final compression since similarities between the files can not
be exploited. You may not care. 

The problem is about easy recovery of individual files plus storing 
and not deleting the older versions of files for some time (users
of the file servers tend to come around crying I have deleted this
important file created a week before accidentally, where can I find
it?).

The way it is done I can expose the directory hierarchy as read-only
to users and they can get the damn file themselves, they just need 
to unzip it. If they were to search through a huge zipfile to find 
it, that could be a problem for them. 




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


ANN: matplotlib-0.70

2004-12-31 Thread John Hunter

matplotlib is a 2D graphics package that produces plots from python
scripts, the python shell, or embeds them in your favorite python GUI
-- wx, gtk, tk, fltk currently supported with qt in the works.  Unlike
many python plotting alternatives is written in python, so it is
easy to extend.  matplotlib is used in the finance industry, web
application servers, and many scientific and enginneering disciplines.
With a large community of users and developers, matplotlib is
approaching the goal of having a full featured, high quality, 2D
plotting library for python.

A lot of development has gone into matplotlib since the last major
release, which I'll summarize here.  For details, see the notes for
the incremental releases at http://matplotlib.sf.net/whats_new.html.

Major changes since matplotlib-0.60

 - The alpha version of the users guide -
   http://matplotlib.sf.net/users_guide.pdf.  There are still a number
   of sections to be completed, but it's a start!

 - The matlab namespace renamed pylab - if you are upgrading from a
   version older than 0.64, please remove site-packages/matplotlib
   before upgrading.  See
   http://matplotlib.sourceforge.net/matlab_to_pylab.py 

 - New plot types: contour plots (contour), polar charts (polar),
   horizontal bar charts (barh), pie charts (pie), sparse matrix
   visualization (spy and spy2).  Eg,
   http://matplotlib.sf.net/screenshots.html#polar_demo

 - Full ipython http://ipython.scipy.org integration in the pylab
   mode for interactive control of matplotlib plots from the python
   shell.

 - A significantly improved interactive toolbar for panning, zooming,
   zoom to rect - see
   http://matplotlib.sf.net/tutorial.html#toolbar2. 

 - New backends: FLTK, Cairo, GTKCairo

 - Text - rotated mathtext, mathtext for postscript, text bounding
   boxes

 - Colormaps - 14 colormaps built-in
   http://matplotlib.sf.net/screenshots.html#pcolor_demo

 - Images - performance optimizations for 4x faster large image
   handling, PIL support, interpolation and colorbar improvements,
   imread

 - Event handling for capturing mouse clicks, movements, keypresses,
   etc. - same pylab interface works across GUIs.  See
   examples/keypress_demo.py, examples/picker_demo.py,
   examples/coords_demo.py

 - set and get matlab style property introspection -
   http://matplotlib.sf.net/examples/set_and_get.py

 - improved dates handling for dates and date string formatting from
   -, eg
   http://matplotlib.sf.net/screenshots.html#finance_work

 - Be sure to check out the 120 examples at
   http://matplotlib.sf.net/examples


  Home page   : http://matplotlib.sourceforge.net
  Downloads   : http://sourceforge.net/projects/matplotlib 
  Screenshots : http://matplotlib.sourceforge.net/screenshots.html
  Tutorial: http://matplotlib.sourceforge.net/tutorial.html
  Credits : http://matplotlib.sourceforge.net/credits.html

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


Re: The Industry choice

2004-12-31 Thread Paul Rubin
Bulba! [EMAIL PROTECTED] writes:
 OK, so what projects and why would you consider Python:
 
 1. clearly unsuitable 

An OS kernel, a high-performance signal processing application like a
video encoder, or maybe a compact embedded application for an 8-bit
microcontroller.  Note that you could do the microcontroller project
with JavaCard.  (Yeah, you could maybe write the outer shell of the
high-performance app in Python, but I mean the part doing the real work.)

 2. plausible but there are sound technical reasons to be wary

A security-critical financial application.

 BTW, I don't think I agree with your statement elsewhere about unit
 tests - if you write a prototype (in any language), why bother with
 unit tests, and if you write security-critical app, maybe the tests
 should be written anyway (again, whatever is the language chosen for
 a project).

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.

I'm also not too impressed with Python's bundled debugging features,
as compared with gcc/gdb.  People have said nice things about some of
the commercial Python environments but I haven't used those.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Paul Rubin
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?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is lambda used for in real code?

2004-12-31 Thread Diez B. Roggisch
 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!

I use them in conjunction with metaclasses and properties:

def _s_item(self, item):
 saw::active 
self.__item = item
self.set_state()
self.indexWidget.setText(%i % item.index)
created = item.created
dt = QDateTime(QDate(created.year, created.month, created.day),
QTime(created.hour, created.minute,created.second))
self.createdWidget.setDateTime(dt)
self.set_text()
self.set_list_items(self.history, item.history)
self.set_list_items(self.trainlog, item.train_log)
self.set_classification_result()

self.adjust_header_sizes()

def _g_item(self):
return self.__item

# the lambda is needed for late-binding so that metaclass-wrapping will
# be in effect.
item = property(_g_item, lambda self, v: self._s_item(v))


The doc string of _s_item contains a token the metaclass is aware of and
creates a wrapper around _s_item. That works nice on methods, but I found
that properties got bound to their functions _before_ the metaclass kicks
in, so the property wasn't called in the wrapped version, resulting in
errors. So I introduced the lambda that makes the method call lazy. Of
course  I could have introduced a 

def _s_item_unwrapped(self, v):
self._s_item(v)

and used that in  the property - but as there are lambdas, I use them :)

And the second def here is not more explanatory, as one has to graps the
internal details of python properties to understand why that extra hoop is
introduced in the first place.
-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speed ain't bad

2004-12-31 Thread Paul Rubin
Bulba! [EMAIL PROTECTED] writes:
 The only thing I'm missing in this picture is knowledge if my script
 could be further optimised (not that I actually need better
 performance, I'm just curious what possible solutions could be). 
 
 Any takers among the experienced guys?

There's another compression program called LHN which is supposed to be
quite a bit faster than gzip, though with somewhat worse compression.
I haven't gotten around to trying it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing a search string

2004-12-31 Thread Fuzzyman
That's not bad going considering you've only run out of alcohol at 6 in
the morning and *then* ask python questions.

Anyway - you could write a charcter-by-character parser function that
would do that in a few minutes...

My 'listquote' module has one - but it splits on commas not whitespace.
Sounds like you're looking for a one-liner though regular
expressions *could* do it...

Regards,

Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html#llistquote

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


Re: The Industry choice

2004-12-31 Thread Christopher Koppler
On Fri, 31 Dec 2004 05:54:05 -0800, Paul Rubin wrote:

 Bulba! [EMAIL PROTECTED] writes:
 OK, so what projects and why would you consider Python:
 
 1. clearly unsuitable 
 
 An OS kernel, a high-performance signal processing application like a
 video encoder, or maybe a compact embedded application for an 8-bit
 microcontroller.

Of course, but those are not areas where I'd consider any
high-level language appropriate. C, Forth and Assembler rule where every
last bit counts, and they will continue to do so. Exceptions like Lisp
Machines are however something to hope for.

  Note that you could do the microcontroller project
 with JavaCard.  (Yeah, you could maybe write the outer shell of the
 high-performance app in Python, but I mean the part doing the real work.)

Hmm, didn't know about JavaCard, but I'd guess without bothering to look
that, like Java's Micro Edition, this features a restricted subset of
Java... Python definitely cannot do that now, but the PyPy future may
(hopefully) change that. And at least Python's beginning to try to
encroach in the very heavily Java-dominated mobile phone software market...

 
 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?

 
 BTW, I don't think I agree with your statement elsewhere about unit
 tests - if you write a prototype (in any language), why bother with
 unit tests, and if you write security-critical app, maybe the tests
 should be written anyway (again, whatever is the language chosen for
 a project).
 
 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.
 
 I'm also not too impressed with Python's bundled debugging features,
 as compared with gcc/gdb.  People have said nice things about some of
 the commercial Python environments but I haven't used those.

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.

-- 
Christopher

In theory, I'm in love with Lisp,
but I hop into bed with Python every chance I get.

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


Re: what would you like to see in a 2nd edition Nutshell? A: Unicode aware scrollable message box in Tk

2004-12-31 Thread Pekka Niiranen
Well,
I have not read the previous version, but
I would like to see an example how to redirect console messages
from scripts to Tk windows in UTF-8/16 for debugging purposes.
(I hate those ordinal not in range(128) messages)
This involves setting font (Arial MS Unicode), scrollbar and
Continue -button (allows script to continue execution).
It could be called Unicode aware scrollable message box in Tk
-pekka-
Alex Martelli wrote:
I'm considering proposing to O'Reilly a 2nd edition of Python in a
Nutshell, that I'd write in 2005, essentially to cover Python 2.3 and
2.4 (the current 1st edition only covers Python up to 2.2).
What I have in mind is not as complete a rewrite as for the 2nd vs 1st
edition of the Cookbook -- Python hasn't changed drastically between 2.2
and 2.4, just incrementally.  Language and built-ins additions I'd of
course cover -- decorators, custom descriptors (already in 2.2 but not
well covered in the 1st edition), importing from zipfiles, extended
slicing of built-in sequences, sets, genexps, ... and also major new
standard library modules such as (in no special order) optparse,
tarfile, bsddb's new stuff, logging, Decimal, cookielib, datetime,
email... and new capabilities of existing modules, such as thread-local
storage.  Outside of the standard library, I was thinking of expanding
the coverage of Twisted and adding just a few things (numarray --
perhaps premature to have it _instead_ of Numeric, though; dateutils,
paramiko, py2app...).  Since the book's size can't change much, I'll
also have to snip some stuff (the pre-email ways to deal with mail, for
example; modules asyncore and asynchat, probably) to make space for all
of the additions.
I haven't take any real decisions about it, yet, except one: I'll keep
covering Tkinter, rather than moving to, say, wxPython (no space to
_add_ wx coverage while leaving Tk intact - having to choose, I still
believe Tkinter coverage is going to help more readers).  Just about
everything else is still to be finalized in my mind...
So, if there's any advice or request about a 2nd edition of the
Nutshell, this is the right time for y'all to let me know.  Feedback is
welcome, either privately or right here.  Thanks in advance -- _and_
apologies in advance because I know I just won't be able to accomodate
all the requests/advice, given the constraints on book size c.
Alex
--
http://mail.python.org/mailman/listinfo/python-list


Re: More baby squeaking - iterators in a class

2004-12-31 Thread M.E.Farmer
Reread Russel Blau post he is spot on with his comments:
Russel Blau wrote:
I don't get that from the passage quoted, at all, although it is
somewhat
opaque. It says that your __iter__() method must *return an object*
with a
next() method; your __iter__() method below doesn't return such an
object,
but instead returns a string. It then says that *if* your class
defines
next(), which yours doesn't, __iter__() can return self.

[spaces inserted; you should note that many newsreaders strip the TAB
character...]

 class R:
   def __init__(self, d):
 self.d=d
 self.i=len(d)
   def __iter__(self):
 if self.i == 0:
   raise StopIteration
 self.i -= 1
   return self.d[self.i]

Solution: replace __iter__ with next in the class definition
above,
then add to the end:

  def __iter__(self):
return self
That works exactly as advertised.

py s = R('54645656')
... s.next()
'6'
... s.next()
'5'
... s.next()
'6'
... s.next()
'5'
... s.next()
'4'
.. s.next()
'6'
... s.next()
'4'
... s.next()
'5'
... s.next()
Traceback (most recent call last):
File input, line 1, in ?
File input, line 7, in next
StopIteration

And the other posters showed you how to create an iterator without a
next() .
Other than having no next() method they still work the same.

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


Re: The Industry choice

2004-12-31 Thread Alex Martelli
Christopher Koppler [EMAIL PROTECTED] wrote:
   ...
   What makes such companies to choose Java over dynamic, productive
   languages like Python?  Are there any viable, technical reasons
   for that?
   ...
  There is a reason very important to major companies.  When you leave
  that company, there will be a *long* line of Java programmers
  waiting to take your place.
  
  IMO learning Python is a matter of few days for Java programmer.
 
 True, but learning to *think* in Python takes a while longer. That static
 straitjacket takes some time to loosen...

Yes to both: learning, particularly with Jython (so one keeps using
already-known Java libraries), is quite fast -- the full benefits take
more time to develop, although even using Python less than ideally can
already be faster.  But for a company to convince itself that the
investment is small and the benefits accrue rapidly -- and keep accruing
in the long term -- can still be quite a leap of faith.


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


Re: Parsing a search string

2004-12-31 Thread Reinhold Birkenfeld
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2004-12-31 Thread Alex Martelli
Christopher Koppler [EMAIL PROTECTED] wrote:

 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

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.  But they don't sell SW nor
consulting services like, say, MS or IBM...


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


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: 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:
http://article.gmane.org/gmane.comp.python.wxpython/17535


-- 
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: 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 i0:
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 interactive input, 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 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 i0:
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 interactive input, 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: 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: 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: 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 http://www.python.org/peps/pep-0309.html
(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: 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: 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  http://[EMAIL PROTECTED] 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 URL:
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 i10:
## 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: 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 i10:

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 i10:
 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 i10:
 ## 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: 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: 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 lambdas 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):
 
snipping wonderful verbosity

 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 python-list@python.org 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.

  mike
-- 
Mike Meyer [EMAIL PROTECTED]  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: 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: 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!

big-evil-grin-wink

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: 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: 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: 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.

pyclass R3:
...def __init__(self, d):
...   self.d=d
...   self.i=len(d)
...def __iter__(self):
...   d,i = self.d, self.i
...   while i0:
...   i-=1
...   yield d[i]
...
pya = R3('qwerty')
pydir(a)
['__doc__', '__init__', '__iter__', '__module__', 'd', 'i']
pyfor 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


  1   2   >