ANN: pinocchio 0.1, extensions for nose unit test framework

2007-03-11 Thread Titus Brown
ANNOUNCING pinocchio v0.1.

pinocchio is a collection of plugins for the 'nose' unit testing framework;
more about that here:

 http://somethingaboutorange.com/mrl/projects/nose/

Basic documentation for pinocchio is available at

 http://darcs.idyll.org/~t/projects/pinocchio/doc/

pinocchio currently contains five plugins:

  * decorator -- allows you to assign tags to tests from a list file;

  * figleafsections -- shows you which tests are executing what code;

  * stopwatch -- lets you pick tests to run based on the last execution time;

  * outputsave -- saves test stdout into individual files, tagged with
   success/failure.

  * spec -- generates specification output from test class/method names.

This is the first package release of pinocchio.

Note that pinocchio *requires* setuptools to be installed, because that
is how nose plugins work!

You can install pinocchio with easy_install, or download this release at

http://darcs.idyll.org/~t/projects/pinocchio-0.1.tar.gz

Documentation is included in the .tar.gz, and you can read the latest
docs online at

 http://darcs.idyll.org/~t/projects/pinocchio/doc/

pinocchio is available under the MIT license.  It is Copyright (C)
2006, 2007 C. Titus Brown, except for the spec plugin which is
Copyright (C) 2007 Michal Kwiatkowski.

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

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


Re: unsigned integer?

2007-03-11 Thread Gabriel Genellina
En Sat, 10 Mar 2007 21:04:00 -0300, Paul Rubin  
http://phr.cx@NOSPAM.invalid escribió:

 Gabriel Genellina [EMAIL PROTECTED] writes:
  If you use %u you get a very large positive value, not +3.
 Exactly, and that's the right value. (unsigned int)(-3) isn't +3.

 The OP specified that the expected result was 3.

Ouch! Yes, sorry, I overlooked it. And the C code just made things more  
confusing.

-- 
Gabriel Genellina

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


Re: How to test if a key in a dictionary exists?

2007-03-11 Thread Paul McGuire
On Mar 10, 9:12 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
  if hist.has_key(outcome):
  hist[outcome] += 1  # if key already exists, increment
  else:
  hist[outcome] = 1   # else create a new key

 You could write that:

hist[outcome] = 1 + hist.get(outcome, 0)

 Or with Python 2.5 you could use

hist = defaultdict(int)
...
hist[outcome] += 1  # automatically initializes to 0 if outcome not found

Often when building a histogram, one knows in advance what the keys
will be.  For instance, when working with data from 0 to 100 and
looking for frequencies by decade, you can initialize the histogram-
dict with:

for i in range(10):
histodict[i] = 0

and then just update the appropriate bucket without having to do any
testing at all:

fibSeqUpTo100 = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
for val in fibSeqUpTo100:
key = val/10
histodict[ key ] += 1

This has the added benefit of including entries for the empty buckets
as well.

-- Paul

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


Re: number generator

2007-03-11 Thread MonkeeSage
On Mar 11, 2:16 am, greg [EMAIL PROTECTED] wrote:
 MonkeeSage wrote:
  this ... requires that M be evenly divisible by N,

 No, it doesn't -- I never said the numbers had
 to be *equal*.

Sorry for not being clear. I was refering to my specific
implementation of the algorithm, not the generic design pattern.

Regards,
Jordan

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-11 Thread Paddy
On Mar 9, 10:30 am, Nick Craig-Wood [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   What if 2 new 'special' comment-like characters were added to Python?:

   1. The WIP (Work In Progress) comment:

 I use # FIXME for this purpose or /* FIXME */ in C etc.

 I have an emacs macro which shows it up in bright red / yellow text so
 it is easy to see and the company has a system which makes a web page
 with a list of all the FIXMEs on.

 FIXME is easy to grep for, language neutral and a lot of people use
 something similar (eg XXX or TODO).

   2. The HALT comment:

 You can so this with triple quotes.  ''' and ''' (if you normally use
   for docstrings)

 Python just ignores strings that lie around.

 --
 Nick Craig-Wood [EMAIL PROTECTED] --http://www.craig-wood.com/nick

Vim will highlight the following comments too:
  #FIXME
  #TODO
  #XXX

- Paddy

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


Help

2007-03-11 Thread Clement
how to use Python/C API 

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


Re: Database module multithreading

2007-03-11 Thread Gabriel Genellina
En Sat, 10 Mar 2007 22:44:43 -0300, Jon Ribbens  
[EMAIL PROTECTED] escribió:

 I don't know, but stock Python 2.5 seems to stick mysterious '.egg'
 files in the site-packages directory when you install things.

Which stock Python? Not the one from www.python.org... If you are  
talking about some Linux distro, ask the packagers...

-- 
Gabriel Genellina

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


Re: Python in a desktop environment

2007-03-11 Thread David Cramer
On Mar 10, 10:52 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 David Cramer wrote:
  If you had an application that you were about to begin development on
  which you wanted to be cross platform (at least Mac and Windows),
  would you suggest using c++ and Python?

 I'd strongly consider a pure python solution (I'd choose wxpython),
 but if I needed to code backend stuff in a lower level language I'd
 use C rather than C++.

Well we want it to be very robust, and python isn't exactly the
fastest language, or one with the lowest overhead :)

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


Parsing Indented Text (like parsing Python)

2007-03-11 Thread Mike Schinkel
Hi,

I'm relatively new to Python but have lots of prior programming experience
as a developer, instructor, and author (ASP/VBScript/SQL Server and
Clipper.)

I'm trying to write an app that parses a text file containing an outline
useing essentially the same indentation rules as Python source code, i.e.
the first level has no indent, the second level has one indent, third level
has two indents, and so on. However, I can't know for sure that the
indentations are tabs or spaces, or even mixed tabs and spaces.  What's
more, I can't know for sure what tab spacing the persons editor was using if
they saved as spaces, i.e. tab='N' spaces where N= (2,3,4,5,6,7,8,...)

Clearly the source code for Python has to figure this out, but I wonder if
anyone knows how to do this in Python. Frankly I'm stumped on how to find an
elegant algorithm that does require multipass parsing and lots of code.  Any
help would be appreciated.

-- 
-Mike Schinkel
http://www.mikeschinkel.com/blogs/
http://www.welldesignedurls.org
http://atlanta-web.org - http://t.oolicio.us






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


Re: Python in a desktop environment

2007-03-11 Thread Diez B. Roggisch
David Cramer schrieb:
 On Mar 10, 10:52 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:
 David Cramer wrote:
 If you had an application that you were about to begin development on
 which you wanted to be cross platform (at least Mac and Windows),
 would you suggest using c++ and Python?
 I'd strongly consider a pure python solution (I'd choose wxpython),
 but if I needed to code backend stuff in a lower level language I'd
 use C rather than C++.
 
 Well we want it to be very robust, and python isn't exactly the
 fastest language, or one with the lowest overhead :)

Erm, and what has _robustness_ with fast  less overhead to do? It's 
exactly the other way round, a python program is much less likely to 
crash that C/C++, and if so in manners that are much easier to manage 
and fix.

I've done extensive GUI-development with PyQt, and can say that it's a 
very productive and powerful combination. And GUI-code usually isn't 
troublesome performance-wise.

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


Re: Python in a desktop environment

2007-03-11 Thread Duncan Booth
David Cramer [EMAIL PROTECTED] wrote:

 On Mar 10, 10:52 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:
 David Cramer wrote:
  If you had an application that you were about to begin development on
  which you wanted to be cross platform (at least Mac and Windows),
  would you suggest using c++ and Python?

 I'd strongly consider a pure python solution (I'd choose wxpython),
 but if I needed to code backend stuff in a lower level language I'd
 use C rather than C++.
 
 Well we want it to be very robust, and python isn't exactly the
 fastest language, or one with the lowest overhead :)
 
So if you want it to be robust it's a no brainer: Python and no C++ or C.

I'd advise you to start off doing it in pure Python, then when you get it 
working see if it is fast enough, and if not profile it and find the 
bottlenecks. Those bits which really do need speeding up you should then 
rewrite using Pyrex, which won't take long at all since it is basically the 
same syntax. Also see whether Psyco helps.

Python can be slow, but if you leverage the built in functionality 
correctly you'll find it isn't much slower than C/C++ for many tasks, and 
can even be faster than you would get from C/C++ without a spending a very 
long time optimising it (that's because people have already spent a very 
long time optimising Python's builtin functionality).

Even if you do eventually find you have to rewrite parts of the code in 
C/C++ you should first have done what you can to optimise it in Python. 
Usually the best way to speed up something which is too slow is to use a 
different algorithm. That sort of change is comparatively easy to do in 
Python but an expensive programming exercise in C/C++. When you come to 
reimplement it then you'll be converting the already optimised code, which 
in many cases will be much easier than writing it in C/C++ from scratch.

If you look at http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprtTR.pdf 
you'll see that, at least for that task, the relative runtimes for C/C++ 
and Python widely overlap. Yes, the C/C++ implementation included some very 
fast ones, but they also included slows ones (and only Python of all the 
languages tested had no unusable implementations). OTOH, time to write the 
programs does not overlap. Of course, since that paper was written Python 
has changed a lot.
-- 
http://mail.python.org/mailman/listinfo/python-list


threading and iterator crashing interpreter

2007-03-11 Thread Janto Dreijer
I have been having problems with the Python 2.4 and 2.5 interpreters
on both Linux and Windows crashing on me. Unfortunately it's rather
complex code and difficult to pin down the source.

So I've been trying to reduce the code. In the process it's started to
crash in different ways. I'm not sure if any of it is related. The
following is only crashing Python 2.5 (r25:51908, Sep 19 2006,
09:52:17) [MSC v.1310 32 bit (Intel)] on win32 in two different(?)
ways.



Using the login1() function will throw a bunch of exceptions the most
interesting of which is:

Exception in thread Thread-34:
Traceback (most recent call last):
  File C:\Python25\lib\threading.py, line 460, in __bootstrap
self.run()
  File C:\Python25\lib\threading.py, line 440, in run
self.__target(*self.__args, **self.__kwargs)
  File Copy of scratchpad.py, line 20, in login1
random.choice(System.sessions).session_iter.next()
RuntimeError: instance.__dict__ not accessible in restricted mode

I'm not concerned with the Python exceptions, but about 40% of the
time it will launch the Visual Studio JIT Debugger with an Unhandled
exception at 0x1e03973e in pythonw.exe: 0xC005: Access violation
reading location 0x2024.

=

Using the login2() function will sometimes (about 30% of the time)
cause the following to be printed out:

Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:


===

Here's the code. Will it be easier to find the problem if I tried
compiling Python myself?

from threading import Thread
import random

def session_iter(f):
# second interpreter
while 1:
yield len(f.__dict__)

class Session:
def __init__(self):
self.session_iter = session_iter(self)

class System:
sessions = []

def login1():
# first interpreter
System.sessions.append(Session())
while 1:
random.choice(System.sessions).session_iter.next()

def login2():
# first interpreter
System.sessions.append(Session())
System.sessions.pop().session_iter.next()

# main interpreter
threads = [Thread(target=login1) for t in range(2000)]
for thread in threads:
thread.start()

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


Re: Parsing Indented Text (like parsing Python)

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 06:34:03 -0300, Mike Schinkel [EMAIL PROTECTED]  
escribió:

 I'm trying to write an app that parses a text file containing an outline
 useing essentially the same indentation rules as Python source code, i.e.
 the first level has no indent, the second level has one indent, third

You can get some ideas from tabnanny.py or reindent.py, but perhaps they  
are too specific at parsing Python code.

I hope this informal description may help:

Start with IC = Previous IC = 0, and a stack with a single 0 element
For each line in the file:
   compute the indentation column IC (that is, count the number of leading  
whitespace characters; perhaps replacing tabs as 8 spaces)
   compare IC with the Previous IC:
same: continue with next line
IC  previous (indent): push IC onto indent stack
IC  previous (dedent):
discard top of stack
look at the new top of stack (but dont discard it); if not the 
same,  
indentation error.
   Previous IC = IC

Note: You can rewrite the above without using Previous IC, only the  
stack... left to the reader :)
Note 2: At each stage, the indentation level is the current stack size.

-- 
Gabriel Genellina

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


Re: Database module multithreading

2007-03-11 Thread Jon Ribbens
In article [EMAIL PROTECTED], Gabriel Genellina wrote:
 I don't know, but stock Python 2.5 seems to stick mysterious '.egg'
 files in the site-packages directory when you install things.
 
 Which stock Python? Not the one from www.python.org...

Yes, the one from www.python.org.
-- 
http://mail.python.org/mailman/listinfo/python-list


a better solution for GUI in python

2007-03-11 Thread ce
Hi,

My company is using python currently for our website. We need to
develop a GUI front-end for our ERP that would be portable (Windows
and Linux).

My question is which solution would be better for the GUI (and easier
to implement)? I knew there are something like wxidgets, QT and pyGTK?
actually we will need some complicated stuff in the GUI and yet I
don't know much about GUI programming.

Any recommendation guys?

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


Re: Python in a desktop environment

2007-03-11 Thread Hendrik van Rooyen
 David Cramer [EMAIL PROTECTED] wrote:

 If you had an application that you were about to begin development on
 which you wanted to be cross platform (at least Mac and Windows),
 would you suggest using c++ and Python?
 
 I'm asking because we were originally thinking about doing c# but
 after attending PyCon this year I'm reconsidering. We are already
 using Python for the website and I figure a c++ backend w/ a Python
 GUI may work really well, and would be pretty easy to port.
 
 Any opinions?
 
Why drag in the C++ ? 
What do you intend to do in it that you can't do in python?
Seems unnecessarily complex to me.
And on a desktop, speed issues are kind of irrelevant - Python
is snappy enough on modern hardware for most things.

My style would be to have the gui connect via pipes to the
local backend as a separate process, with a third process if there
are any communications needed to off box dbs.   But that is just
the way I think - YMMV

- Hendrik

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


Re: distributed queue?

2007-03-11 Thread Hendrik van Rooyen
 Paul Rubin http://[EMAIL PROTECTED] wrote:

 Bjoern Schliessmann [EMAIL PROTECTED] writes:
  (Why does everyone think that concurrency equals usage of
  multiple threads?)
 
 Well, it doesn't necessarily, but that's easiest a lot of the time.
 
  Try Twisted for your networking needs. 
 
 I should try to understand Twisted better one of these days, but it's
 much more confusing than threads.  Also, the function I want to
 parallelize does blocking operations (database lookups), so in Twisted
 I'd have to figure out some way to do them asynchronously.

I would think of making 'pullers' in the remote machines in front of 
whatever it is you are making parallel to get the next thing to do, 
from a 'queue server' in the originating machine to distribute the 
stuff.

I am not sure if Pyro can help you as I have only read about it and 
not used it but I think its worth a look. If it were a one on one
setup I would not hesitate to recommend it but I can't remember 
if it is any good for one to many scenarios.

- Hendrik


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


Re: Python in a desktop environment

2007-03-11 Thread ce
On Mar 11, 12:26 pm, David Cramer [EMAIL PROTECTED] wrote:
 On Mar 10, 10:52 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:

  David Cramer wrote:
   If you had an application that you were about to begin development on
   which you wanted to be cross platform (at least Mac and Windows),
   would you suggest using c++ and Python?

  I'd strongly consider a pure python solution (I'd choose wxpython),
  but if I needed to code backend stuff in a lower level language I'd
  use C rather than C++.

 Well we want it to be very robust, and python isn't exactly the
 fastest language, or one with the lowest overhead :)

only one word caught my attention robust.. do u mean python is not
robust???
if this is your feeling, i don't recommend u to reconsider anymore,
turn back to ur previous programming language (what did'ya say it
was??? c# .. i remember one ad. about it's robustness .. a piece of
jelly!)

and by the way if u know something about C++, code the GUI with QT
(which would make it portable), and enjoy a high speed execution :P

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


Re: distributed queue?

2007-03-11 Thread Irmen de Jong
Paul Rubin wrote:
 Does anyone have an implementation of a distributed queue?  I.e. I
 have a long running computation f(x) and I'd like to be able to
 evaluate it (for different values of x) on a bunch of different
 computers simultaneously, the usual worker thread pattern except
 distributed across a network.  I guess this is pretty easy to write
 with a centralized socket listener that dispatches requests through a
 Queue to multiple threads on the same machine, each talking
 synchronously to a server socket.  I wonder if something like it
 already exists.  I see a little bit of discussion in the newsgroup
 archive but no obvious pointers to code.
 
 Thanks.

Pyro (http://pyro.sf.net) contains 2 examples that do just this.
One is a distributed merge sort / md5 cracker, the other is
distributed prime factorization of a set of numbers.

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


Re: threading and iterator crashing interpreter

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 07:32:04 -0300, Janto Dreijer [EMAIL PROTECTED]  
escribió:

 I have been having problems with the Python 2.4 and 2.5 interpreters
 on both Linux and Windows crashing on me. Unfortunately it's rather
 complex code and difficult to pin down the source.

 So I've been trying to reduce the code. In the process it's started to
 crash in different ways. I'm not sure if any of it is related. The
 following is only crashing Python 2.5 (r25:51908, Sep 19 2006,
 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 in two different(?)
 ways.

 

 Using the login1() function will throw a bunch of exceptions the most
 interesting of which is:

 Exception in thread Thread-34:
 Traceback (most recent call last):
   File C:\Python25\lib\threading.py, line 460, in __bootstrap
 self.run()
   File C:\Python25\lib\threading.py, line 440, in run
 self.__target(*self.__args, **self.__kwargs)
   File Copy of scratchpad.py, line 20, in login1
 random.choice(System.sessions).session_iter.next()
 RuntimeError: instance.__dict__ not accessible in restricted mode

 From the error message, you appear to be using some form of restricted  
execution - RExec or similar. I didn't try that way, but using the normal  
mode, I got this different exception instead (using login1):

Exception in thread Thread-85:
Traceback (most recent call last):
   File c:\apps\python\lib\threading.py, line 460, in __bootstrap
 self.run()
   File c:\apps\python\lib\threading.py, line 440, in run
 self.__target(*self.__args, **self.__kwargs)
   File crash.py, line 20, in login1
 random.choice(System.sessions).session_iter.next()
ValueError: generator already executing

It appears to indicate that you must syncronize the generators.
Adding a Lock object to Session appears to work OK:

class Session:
 def __init__(self):
 self.lock = Lock()
 self.session_iter = session_iter(self)

def login1():
 # first interpreter
 System.sessions.append(Session())
 while 1:
 session = random.choice(System.sessions)
 session.lock.acquire()
 session.session_iter.next()
 session.lock.release()

Your login2 version does not generate any error on my PC.

-- 
Gabriel Genellina

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


Re: a better solution for GUI in python

2007-03-11 Thread StD
On 11 Mrz., 12:03, ce [EMAIL PROTECTED] wrote:
 Hi,

 My company is using python currently for our website. We need to
 develop a GUI front-end for our ERP that would be portable (Windows
 and Linux).

 My question is which solution would be better for the GUI (and easier
 to implement)? I knew there are something like wxidgets, QT and pyGTK?
 actually we will need some complicated stuff in the GUI and yet I
 don't know much about GUI programming.

 Any recommendation guys?

I'd recommend pyGTK. It's easy to use, delivers astonishing results
and is perfectly portable as far as I know. I'm working with it
myself, having the goal of simplicity as well as portability and I got
to say, it works! Hope that was helpful.

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


Re: Database module multithreading

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 07:55:15 -0300, Jon Ribbens  
[EMAIL PROTECTED] escribió:

 In article [EMAIL PROTECTED],  
 Gabriel Genellina wrote:
 I don't know, but stock Python 2.5 seems to stick mysterious '.egg'
 files in the site-packages directory when you install things.

 Which stock Python? Not the one from www.python.org...

 Yes, the one from www.python.org.

Those .egg must come from other installed packages...

-- 
Gabriel Genellina

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


Re: a better solution for GUI in python

2007-03-11 Thread Paul Rubin
ce [EMAIL PROTECTED] writes:
 My company is using python currently for our website. We need to
 develop a GUI front-end for our ERP that would be portable (Windows
 and Linux).

Some reason not to use a browser interface instead of a client gui?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a better solution for GUI in python

2007-03-11 Thread Bjoern Schliessmann
ce wrote:
 My question is which solution would be better for the GUI (and
 easier to implement)? I knew there are something like wxidgets,

(wxWidgets. It's the C++ lib, its Python bindings are wxPython)

 QT 

(same as above, it's called pyQt. Check licensing, it's not as
liberal as the others'.)

 and pyGTK? actually we will need some complicated stuff in the GUI
 and yet I don't know much about GUI programming.
 
 Any recommendation guys?

Mostly matter of taste. Without any further details of your needs,
no experienced people will be able to help.

Why don't you go to the projects' homepages and read, and perhaps
check a tutorial.

Though biased, this may help:

http://www.wxwidgets.org/wiki/index.php/WxWidgets_Compared_To_Other_Toolkits

(it's for the C++ original only, but much applies to python
bindings)

Regards,


Björn

-- 
BOFH excuse #137:

User was distributing pornography on server; system seized by FBI.

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


Re: a better solution for GUI in python

2007-03-11 Thread Bjoern Schliessmann
StD wrote:

 I'd recommend pyGTK. It's easy to use, delivers astonishing
 results and is perfectly portable as far as I know. 

And how does it look on Windows? :)

 I'm working with it myself, having the goal of simplicity as well
 as portability and I got to say, it works! Hope that was helpful.

Could say the same about wxWidgets, and Qt (the latter only with C++
though).

Regards,


Björn

-- 
BOFH excuse #52:

Smell from unhygienic janitorial staff wrecked the tape heads

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


Re: Database module multithreading

2007-03-11 Thread Jon Ribbens
In article [EMAIL PROTECTED], Gabriel Genellina wrote:
 I don't know, but stock Python 2.5 seems to stick mysterious '.egg'
 files in the site-packages directory when you install things.

 Which stock Python? Not the one from www.python.org...

 Yes, the one from www.python.org.
 
 Those .egg must come from other installed packages...

My mistake, they are .egg-info. And they certainly do come from
stock Python 2.5 from www.python.org and not anything else. They
are installed by distutils/command/install_egg_info, which is
automatically called by 'python setup.py install'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threading and iterator crashing interpreter

2007-03-11 Thread Bjoern Schliessmann
Janto Dreijer wrote:

 I have been having problems with the Python 2.4 and 2.5
 interpreters on both Linux and Windows crashing on me.

I don't understand -- does the interpreter crash (segfault) or is
just your program terminating due to unhandled exceptions?

Regards,


Björn

-- 
BOFH excuse #32:

techtonic stress

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


Re: a better solution for GUI in python

2007-03-11 Thread ce
On Mar 11, 3:05 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
 ce [EMAIL PROTECTED] writes:
  My company is using python currently for our website. We need to
  develop a GUI front-end for our ERP that would be portable (Windows
  and Linux).

 Some reason not to use a browser interface instead of a client gui?

it is a matter of input speed only!
every record posses some calculations and sometimes fresh data from
the database! which i think would be slower in the browser than the
local gui client.
I know that i can implement the functionality in the browser using
javascripts, however, i don't know wither it would be as effective as
a local gui or not and which is more convenient.

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


Re: a better solution for GUI in python

2007-03-11 Thread Jarek Zgoda
Bjoern Schliessmann napisał(a):

 I'd recommend pyGTK. It's easy to use, delivers astonishing
 results and is perfectly portable as far as I know. 
 
 And how does it look on Windows? :)

On styled Windows XP it looks like any other styled application
(counting  those Qt and wx based). On Windows 2000 or unstyled XP since
GTK 2.10 it looks far better than Qt3 applications and nearly as good as
Win32 native applications (including wx based) or Qt4.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threading and iterator crashing interpreter

2007-03-11 Thread Janto Dreijer
On Mar 11, 2:20 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
 Janto Dreijer wrote:
  I have been having problems with the Python 2.4 and 2.5
  interpreters on both Linux and Windows crashing on me.

 I don't understand -- does the interpreter crash (segfault) or is
 just your program terminating due to unhandled exceptions?

Segfault.

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


Re: threading and iterator crashing interpreter

2007-03-11 Thread Janto Dreijer
On Mar 11, 1:46 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Sun, 11 Mar 2007 07:32:04 -0300, Janto Dreijer [EMAIL PROTECTED]
 escribió:



  I have been having problems with the Python 2.4 and 2.5 interpreters
  on both Linux and Windows crashing on me. Unfortunately it's rather
  complex code and difficult to pin down the source.

  So I've been trying to reduce the code. In the process it's started to
  crash in different ways. I'm not sure if any of it is related. The
  following is only crashing Python 2.5 (r25:51908, Sep 19 2006,
  09:52:17) [MSC v.1310 32 bit (Intel)] on win32 in two different(?)
  ways.

  

  Using the login1() function will throw a bunch of exceptions the most
  interesting of which is:

  Exception in thread Thread-34:
  Traceback (most recent call last):
File C:\Python25\lib\threading.py, line 460, in __bootstrap
  self.run()
File C:\Python25\lib\threading.py, line 440, in run
  self.__target(*self.__args, **self.__kwargs)
File Copy of scratchpad.py, line 20, in login1
  random.choice(System.sessions).session_iter.next()
  RuntimeError: instance.__dict__ not accessible in restricted mode

  From the error message, you appear to be using some form of restricted
 execution - RExec or similar. I didn't try that way, but using the normal
 mode, I got this different exception instead (using login1):

 Exception in thread Thread-85:
 Traceback (most recent call last):
File c:\apps\python\lib\threading.py, line 460, in __bootstrap
  self.run()
File c:\apps\python\lib\threading.py, line 440, in run
  self.__target(*self.__args, **self.__kwargs)
File crash.py, line 20, in login1
  random.choice(System.sessions).session_iter.next()
 ValueError: generator already executing

 It appears to indicate that you must syncronize the generators.
 Adding a Lock object to Session appears to work OK:

 class Session:
  def __init__(self):
  self.lock = Lock()
  self.session_iter = session_iter(self)

 def login1():
  # first interpreter
  System.sessions.append(Session())
  while 1:
  session = random.choice(System.sessions)
  session.lock.acquire()
  session.session_iter.next()
  session.lock.release()

 Your login2 version does not generate any error on my PC.

 --
 Gabriel Genellina

As far as I can tell I'm not running it from restricted mode
explicitly.

The reason I'm doing the random.choice() is so I don't have a handle
(session in this case) that would prevent it from being garbage
collected. I am not bothered by the Python-level Exceptions. I am
bothered by the interpreter throwing a segfault. What I suspect is
happening is the Session object is deallocated, while it still has a
reference from within the iterator.

It's quite difficult to reproduce these bugs consistently. You might
need to run it a few times.

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

Re: Database module multithreading

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 09:19:51 -0300, Jon Ribbens  
[EMAIL PROTECTED] escribió:

 In article [EMAIL PROTECTED],  
 Gabriel Genellina wrote:
 I don't know, but stock Python 2.5 seems to stick mysterious '.egg'
 files in the site-packages directory when you install things.

 Which stock Python? Not the one from www.python.org...

 Yes, the one from www.python.org.

 Those .egg must come from other installed packages...

 My mistake, they are .egg-info. And they certainly do come from
 stock Python 2.5 from www.python.org and not anything else. They
 are installed by distutils/command/install_egg_info, which is
 automatically called by 'python setup.py install'.

Ah! Those files contain metadata about the installed packages. See  
http://docs.python.org/whatsnew/whatsnew25.html , but I think the actual  
version is http://www.python.org/dev/peps/pep-0345/ . Anyway, nowhere says  
that the PKG-INFO files are actually copied as packagename.egg-info

-- 
Gabriel Genellina

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


RE: Parsing Indented Text (like parsing Python)

2007-03-11 Thread Mike Schinkel
Gabriel Genellina wrote:
 Start with IC = Previous IC = 0, and a stack with a single 0 
 element For each line in the file:
compute the indentation column IC (that is, count the 
 number of leading whitespace characters; perhaps replacing 
 tabs as 8 spaces)
compare IC with the Previous IC:
   same: continue with next line
   IC  previous (indent): push IC onto indent stack
   IC  previous (dedent):
   discard top of stack
   look at the new top of stack (but dont discard 
 it); if not the same, indentation error.
Previous IC = IC

I went away and reviewed this, but it appears it doesn't tackle the
difficult part which was what made me ask the question in the first place.  

The problem is, how do I figure out how many spaces represent a tab? In one
case, someone could have their editor configured to allow tabs to use 3
spaces and the user could intermingle tabs and spaces. In other cases, a
user might have their editor configured to have a tab equal 8 spaces yet
also intermingle tabs and spaces. When a human looks at the document it is
obvious the setting but how can I make it obvious to my program?  

I could force the user to specify tabwidth at the top of the file, but I'd
rather not. And since Python doesn't either, I know it is possible to write
a parser to do this. I just don't know how.

-- 
-Mike Schinkel
http://www.mikeschinkel.com/blogs/
http://www.welldesignedurls.org
http://atlanta-web.org - http://t.oolicio.us

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


Re: Parsing Indented Text (like parsing Python)

2007-03-11 Thread Stef Mientki
 
 The problem is, how do I figure out how many spaces represent a tab? In one
 case, someone could have their editor configured to allow tabs to use 3
 spaces and the user could intermingle tabs and spaces. In other cases, a
 user might have their editor configured to have a tab equal 8 spaces yet
 also intermingle tabs and spaces. When a human looks at the document it is
 obvious the setting but how can I make it obvious to my program?  
then statistics can do it too.


-- 
cheers,
Stef Mientki
http://pic.flappie.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threading and iterator crashing interpreter

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 09:47:34 -0300, Janto Dreijer [EMAIL PROTECTED]  
escribió:

 As far as I can tell I'm not running it from restricted mode
 explicitly.

This error is rather strange then:

  RuntimeError: instance.__dict__ not accessible in restricted mode

restricted mode means that the current builtins are not the standard  
builtins.


 The reason I'm doing the random.choice() is so I don't have a handle
 (session in this case) that would prevent it from being garbage
 collected. I am not bothered by the Python-level Exceptions. I am
 bothered by the interpreter throwing a segfault. What I suspect is
 happening is the Session object is deallocated, while it still has a
 reference from within the iterator.

But on your code Session objects are never deleted; they stay inside  
System.sessions. Having an extra reference (the session variable) doesnt  
matter.

 It's quite difficult to reproduce these bugs consistently. You might
 need to run it a few times.

At least, the problem of using the same generator from different threads  
still remains, if you don't use my modified code. In general, when using  
multiple threads you always need some way to syncronize access to shared  
objects. You are lucky with Sessions because append is an atomic operation  
on lists; for more information see  
http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm

-- 
Gabriel Genellina

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


Re: Parsing Indented Text (like parsing Python)

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 10:09:57 -0300, Mike Schinkel [EMAIL PROTECTED]  
escribió:

 The problem is, how do I figure out how many spaces represent a tab? In

You can't, unless you have more context.

 one
 case, someone could have their editor configured to allow tabs to use 3
 spaces and the user could intermingle tabs and spaces. In other cases, a
 user might have their editor configured to have a tab equal 8 spaces yet
 also intermingle tabs and spaces. When a human looks at the document it  
 is
 obvious the setting but how can I make it obvious to my program?

it is obvious the setting?
How do you infer that? From other properties of the document, semantics?
Just from the content, and the number of tabs and spaces, you can't get  
anything.

 I could force the user to specify tabwidth at the top of the file, but  
 I'd
 rather not. And since Python doesn't either, I know it is possible to  
 write
 a parser to do this. I just don't know how.

Python simply assumes 8 spaces per tab.
If your Python source ONLY uses tabs, or ONLY spaces, it doesn't matter.  
If you mix tabs+spaces, Python simple replaces each tab by 8 spaces. If  
you edited that using 4 spaces, Python will get it wrong. That's why all  
people always say never mix tabs and spaces

If you know somehow that a certain block -using tabs- has the same  
indentation that another block -using spaces- you could infer the number  
of spaces per tab.

-- 
Gabriel Genellina

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


RE: Parsing Indented Text (like parsing Python)

2007-03-11 Thread Mike Schinkel
Gabriel Genellina wrote:
  The problem is, how do I figure out how 
  many spaces represent a tab? 
 
 You can't, unless you have more context.

How does Python do it?

  one case, someone could have their editor configured to
  allow tabs to use 3 spaces and the user could
  intermingle tabs and spaces. In other cases, a user
  might have their editor configured to have a tab equal
  8 spaces yet also intermingle tabs and spaces. When a
  human looks at the document it is obvious the setting
  but how can I make it obvious to my program?
  
 it is obvious the setting? How do you infer that? From
 other properties of the document, semantics? Just from
 the content, and the number of tabs and spaces, you can't
 get anything.

From looking at it. It might require changing tab widths in the editor, but
one setting will make it clear.

  I could force the user to specify tabwidth at the top
  of the file, but I'd rather not. And since Python
  doesn't either, I know it is possible to write a parser
  to do this. I just don't know how.
  
 Python simply assumes 8 spaces per tab. If your Python
 source ONLY uses tabs, or ONLY spaces, it doesn't matter.
 If you mix tabs+spaces, Python simple replaces each tab
 by 8 spaces. If you edited that using 4 spaces, Python
 will get it wrong. That's why all people always say
 never mix tabs and spaces

Ah.  I didn't know that.  Like I said at first, I am new to Python (but I've
been reading a lot about it!  3 books thus far. Nutshell, Cookbook,
wxPython)

Okay, I'll just use a directive at the top of the file and let the user
specify.  Not perfect, but such is life.

Thanks again.

-- 
-Mike Schinkel
http://www.mikeschinkel.com/blogs/
http://www.welldesignedurls.org
http://atlanta-web.org - http://t.oolicio.us

 

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


Re: Python books?

2007-03-11 Thread Tommy Nordgren

On 9 mar 2007, at 04.06, Tommy Nordgren wrote:

 Could some kind soul please recommend a few text books on Python 2.5
 and it's class library?

I've found one interesting text book on Python:
Mark Lutz - Programming Python, 3rd Edition.
How do you rate it?
One of the reasons I find it interesting is because of it's hefty  
page count
- over 1500 pages.
--
Home is not where you are born, but where your heart finds peace -
Tommy Nordgren, The dying old crone
[EMAIL PROTECTED]


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


Re: threading and iterator crashing interpreter

2007-03-11 Thread Janto Dreijer
On Mar 11, 3:27 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Sun, 11 Mar 2007 09:47:34 -0300, Janto Dreijer [EMAIL PROTECTED]
 escribió:

  As far as I can tell I'm not running it from restricted mode
  explicitly.

 This error is rather strange then:

   RuntimeError: instance.__dict__ not accessible in restricted mode

 restricted mode means that the current builtins are not the standard
 builtins.

Googling says Some googling suggests that this error is a hint that a
Python object created in one subinterpreter is being used in a
different subinterpreter.

  The reason I'm doing the random.choice() is so I don't have a handle
  (session in this case) that would prevent it from being garbage
  collected. I am not bothered by the Python-level Exceptions. I am
  bothered by the interpreter throwing a segfault. What I suspect is
  happening is the Session object is deallocated, while it still has a
  reference from within the iterator.

 But on your code Session objects are never deleted; they stay inside
 System.sessions. Having an extra reference (the session variable) doesnt
 matter.

Hmmm. You're right.

  It's quite difficult to reproduce these bugs consistently. You might
  need to run it a few times.

 At least, the problem of using the same generator from different threads
 still remains, if you don't use my modified code. In general, when using
 multiple threads you always need some way to syncronize access to shared
 objects. You are lucky with Sessions because append is an atomic operation
 on lists; for more information see  
 http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-threa...

Again you're right. But even putting a try-except:return around the
random.choice still manages to break the interpreter. I'm not looking
for any meaningful output really. I just want it not to break.

Like I said, this is just watered down code to try and isolate the
problem.

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

Re: a better solution for GUI in python

2007-03-11 Thread Casey Hawthorne
For a browser interface have you thought of Ajax and possibly WPF/E?

http://en.wikipedia.org/wiki/AJAX

http://en.wikipedia.org/wiki/Windows_Presentation_Foundation
--
Regards,
Casey
-- 
http://mail.python.org/mailman/listinfo/python-list


Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
in case it's relevant.)

 x, y = 0.0, -0.0
 x, y
(0.0, 0.0)
 x, y = -0.0, 0.0
 x, y
(-0.0, -0.0)

I would have expected y to be -0.0 in the first case, and 0.0 in the
second.  Should the above be considered a bug, or is Python not
expected to honour signs of zeros?  I'm working in a situation
involving complex arithmetic where branch cuts, and hence signed
zeros, are important, and it would be handy if the above code could be
relied upon to do the right thing.

Mark

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Dan Bishop
On Mar 11, 9:31 am, Mark Dickinson [EMAIL PROTECTED] wrote:
 I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
 in case it's relevant.)

  x, y = 0.0, -0.0
  x, y
 (0.0, 0.0)
  x, y = -0.0, 0.0
  x, y

 (-0.0, -0.0)

 I would have expected y to be -0.0 in the first case, and 0.0 in the
 second.  Should the above be considered a bug, or is Python not
 expected to honour signs of zeros?  I'm working in a situation
 involving complex arithmetic where branch cuts, and hence signed
 zeros, are important, and it would be handy if the above code could be
 relied upon to do the right thing.

IIRC, float.__repr__ just does whatever libc does.  Have you tried
using printf(%g, %g, 0.0, -0.0) in a C program?

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread jim-on-linux
On Sunday 11 March 2007 10:31, Mark Dickinson 
wrote:
 I get the following behaviour on Python 2.5 (OS
 X 10.4.8 on PowerPC, in case it's relevant.)

  x, y = 0.0, -0.0
  x, y

 (0.0, 0.0)

  x, y = -0.0, 0.0
  x, y

 (-0.0, -0.0)

 I would have expected y to be -0.0 in the first
 case, and 0.0 in the second.  Should the above
 be considered a bug, or is Python not expected
 to honour signs of zeros?  I'm working in a
 situation involving complex arithmetic where
 branch cuts, and hence signed zeros, are
 important, and it would be handy if the above
 code could be relied upon to do the right
 thing.

 Mark



This works for some reason 
instead of x,y =  -0.0, 0.0
clumpy but the results are right.

x = -0.0
y= 0.0
 
x,y
(-0.0, 0.0)




jim-on-linux
http:\\inqvista.com







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


Re: PIL: reading bytes from Image

2007-03-11 Thread cyberco
Thanks,

I've tried the StringIO option as follows:

=
img = Image.open('/some/path/img.jpg')
img.thumbnail((640,480))
file = StringIO, StringIO()
img.save(file, 'JPEG')

=

But it gives me:

=

exceptions.TypeError Traceback (most
recent call last)

C:\Python24\lib\site-packages\PIL\Image.py in save(self, fp, format,
**params)
   1303
   1304 try:
- 1305 save_handler(self, fp, filename)
   1306 finally:
   1307 # do what we can to clean up

C:\Python24\lib\site-packages\PIL\JpegImagePlugin.py in _save(im, fp,
filename)
407 )
408
-- 409 ImageFile._save(im, fp, [(jpeg, (0,0)+im.size, 0,
rawmode)])
410
411 def _save_cjpeg(im, fp, filename):

C:\Python24\lib\site-packages\PIL\ImageFile.py in _save(im, fp, tile)
464 bufsize = max(MAXBLOCK, im.size[0] * 4) # see RawEncode.c
465 try:
-- 466 fh = fp.fileno()
467 fp.flush()
468 except AttributeError:

TypeError: descriptor 'fileno' of 'file' object needs an argument
=

It looks similar to the code in Sparklines except for the fact that
the latter creates an Image from scratch.

2B

 Saving the image, in a
 format your client understands, to a file like object like
 StringIO.StringIO is an easy path to take.

 Sparklines shows this in action:

 http://bitworking.org/projects/sparklines/

 max


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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Terry Reedy

Dan Bishop [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| On Mar 11, 9:31 am, Mark Dickinson [EMAIL PROTECTED] wrote:
|  I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
|  in case it's relevant.)
| 
|   x, y = 0.0, -0.0
|   x, y
|  (0.0, 0.0)
|   x, y = -0.0, 0.0
|   x, y
| 
|  (-0.0, -0.0)
|| IIRC, float.__repr__ just does whatever libc does.  Have you tried
| using printf(%g, %g, 0.0, -0.0) in a C program?

Detailed FP behavior like this is system (and yes, libc) dependent.  On 
WinXP
IDLE 1.1.3
 x,y = 0.0, -0.0
 x,y
(0.0, 0.0)
 x,y = -0.0, 0.0
 x,y
(0.0, 0.0)
 -0.0
0.0

Terry Jan Reedy



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


Re: Parsing Indented Text (like parsing Python)

2007-03-11 Thread Paul McGuire
On Mar 11, 8:37 am, Gabriel Genellina [EMAIL PROTECTED]
wrote:
  
 If you mix tabs+spaces, Python simple replaces each tab by 8 spaces.


Are you sure about this?  This is not the tab problem I am familiar
with in the past.  In the following sample, the columnar text labeled
'col2' should all be aligned at column 9:

xtabcol2
xxxtabcol2
  tabcol2

In the first line, the tab is replaced with 7 spaces, the second line
by 5, and the third line by 6.  So tab replacement is a bit more
involved than simply s/\t//g.

As I recall, the number of spaces to replace a tab by is something
like 8-(col % 8) where col is the column location of the tab with the
left most column being 0.

-- Paul

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


Re: PIL: reading bytes from Image

2007-03-11 Thread Max Erickson
cyberco [EMAIL PROTECTED] wrote:

 Thanks,
 
 I've tried the StringIO option as follows:
 
 =
 img = Image.open('/some/path/img.jpg')
 img.thumbnail((640,480))
 file = StringIO, StringIO()

Is the above line exactly what you tried? If it is, the comma and 
space in the line are likely the problem. Try either:

from StringIO import StringIO 
file=StringIO()

or

import StringIO
file=StringIO.StringIO()

(using file as a variable name can cause issues if you later want 
access to the built in object 'file')

The following:

 import Image
 import StringIO
 im=Image.new('RGB', (100,100))
 fp=StringIO.StringIO()
 im.save(fp, 'jpeg')
 len(fp.getvalue())
823

Works for me on python 2.5 on windows.


max

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 12:13 pm, Terry Reedy [EMAIL PROTECTED] wrote:
 Dan Bishop [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]
 | On Mar 11, 9:31 am, Mark Dickinson [EMAIL PROTECTED] wrote:
 |  I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
 |  in case it's relevant.)
 | 
 |   x, y = 0.0, -0.0
 |   x, y
 |  (0.0, 0.0)
 |   x, y = -0.0, 0.0
 |   x, y
 | 
 |  (-0.0, -0.0)
 || IIRC, float.__repr__ just does whatever libc does.  Have you tried
 | using printf(%g, %g, 0.0, -0.0) in a C program?

 Detailed FP behavior like this is system (and yes, libc) dependent.  On
 WinXP
 IDLE 1.1.3 x,y = 0.0, -0.0
  x,y
 (0.0, 0.0)
  x,y = -0.0, 0.0
  x,y
 (0.0, 0.0)
  -0.0

 0.0

 Terry Jan Reedy

Interesting.  So on Windows there's probably no hope of what I want to
do working.
But on a platform where the C library does the right thing with signed
zeros, this
behaviour is still a little surprising.  I guess what's happening is
that there's
some optimization that avoids creating two separate float objects for
a float literal
that appears twice, and that optimization doesn't see the difference
between 0. and -0.

 x, y = 0., -0.
 id(x) == id(y)
True

jim-on-linux's solution works in the interpreter, but not in a script,
presumably because we've got file-wide optimization rather than
line-by-line optimization.

#test.py
x = -0.0
y = 0.0
print x, y
#end test.py

 import test
-0.0 -0.0

Mark

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


Re: Parsing Indented Text (like parsing Python)

2007-03-11 Thread John Nagle
Mike Schinkel wrote:
 Gabriel Genellina wrote:

That's why all people always say
never mix tabs and spaces

 That's the one rule in this area Python ought to enforce.
If you've got that, you can convert tabs to spaces, or vice
versa, safely.

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


Re: Best place for a function?

2007-03-11 Thread Bruno Desthuilliers
Inyeol Lee a écrit :
 On Wed, Mar 07, 2007 at 05:27:04PM -0500, Sergio Correia wrote:
 
I'm writing a class, where one of the methods is kinda complex. The
method uses a function which I know for certain will not be used
anywhere else. This function does not require anything from self, only
the args passed by the method.

Where should I put the function?
 
 
 Use staticmethod. It's a normal function with class namespace.

What do you think the OP will gain from making a simple helper function 
a staticmethod ? Apart from extra lookup time ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing Indented Text (like parsing Python)

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 13:12:20 -0300, Paul McGuire [EMAIL PROTECTED]  
escribió:

 On Mar 11, 8:37 am, Gabriel Genellina [EMAIL PROTECTED]
 wrote:

 If you mix tabs+spaces, Python simple replaces each tab by 8 spaces.

 As I recall, the number of spaces to replace a tab by is something
 like 8-(col % 8) where col is the column location of the tab with the
 left most column being 0.

Yes, each tab advances to the next multiple-of-8 column. The problem is  
that 8 is fixed.

-- 
Gabriel Genellina

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


Re: Python in a desktop environment

2007-03-11 Thread Bruno Desthuilliers
David Cramer a écrit :
 If you had an application that you were about to begin development on
 which you wanted to be cross platform (at least Mac and Windows),
 would you suggest using c++ and Python?
 
 I'm asking because we were originally thinking about doing c# but
 after attending PyCon this year I'm reconsidering. We are already
 using Python for the website and I figure a c++ backend w/ a Python
 GUI may work really well, and would be pretty easy to port.
 
 Any opinions?
 
Yes : forget about the c++ backend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Duncan Booth
Mark Dickinson [EMAIL PROTECTED] wrote:

 I guess what's happening is that there's some optimization that avoids
 creating two separate float objects for a float literal that appears
 twice, and that optimization doesn't see the difference between 0. and
 -0. 

Don't guess. Test.

 def f():
x = 0.0
y = -0.0
return x, y

 dis.dis(f)
  2   0 LOAD_CONST   1 (0.0)
  3 STORE_FAST   0 (x)

  3   6 LOAD_CONST   1 (0.0)
  9 STORE_FAST   1 (y)

  4  12 LOAD_FAST0 (x)
 15 LOAD_FAST1 (y)
 18 BUILD_TUPLE  2
 21 RETURN_VALUE

Yes. Just the one constant there.


Tim Peters wrote in 
http://blog.gmane.org/gmane.comp.python.devel/day=20050409:

 All Python behavior in the presence of a NaN, infinity, or signed zero
 is a platform-dependent accident.  This is because C89 has no such
 concepts, and Python is written to the C89 standard.  It's not easy to
 fix across all platforms (because there is no portable way to do so in
 standard C), although it may be reasonably easy to fix if all anyone
 cares about is gcc and MSVC (every platform C compiler has its own set
 of gimmicks for dealing with these things).

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


Re: Python in a desktop environment

2007-03-11 Thread Bruno Desthuilliers
David Cramer a écrit :
 On Mar 10, 10:52 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:
 
David Cramer wrote:

If you had an application that you were about to begin development on
which you wanted to be cross platform (at least Mac and Windows),
would you suggest using c++ and Python?

I'd strongly consider a pure python solution (I'd choose wxpython),
but if I needed to code backend stuff in a lower level language I'd
use C rather than C++.
 
 
 Well we want it to be very robust,

Which is a pretty good reason to favor Python over C or C++.

 and python isn't exactly the
 fastest language, or one with the lowest overhead :)

It's not exactly one of the slowest languages nor one with the highest 
overhead neither. Chances are you'll have a fully-functional production 
level app in Python *way* before you have a first alpha in C++. If by 
then you *really* have some performance problem, it will be time to port 
the relevant modules to C extensions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Mark Dickinson [EMAIL PROTECTED] wrote:

 I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
 in case it's relevant.)
 
  x, y = 0.0, -0.0
  x, y
 (0.0, 0.0)
  x, y = -0.0, 0.0
  x, y
 (-0.0, -0.0)
 
 I would have expected y to be -0.0 in the first case, and 0.0 in the
 second.  Should the above be considered a bug, or is Python not
 expected to honour signs of zeros?  I'm working in a situation
 involving complex arithmetic where branch cuts, and hence signed
 zeros, are important, and it would be handy if the above code could be
 relied upon to do the right thing.

Looks to me like you've found a bug with the parser/compiler:

 c=compile('-0.0,0.0', 'eval', 'eval')
 eval(c)
(-0.0, -0.0)
 dis.dis(c)
  1   0 LOAD_CONST   1 ((-0.0, -0.0))
  3 RETURN_VALUE 

Similar problems appear in parsing display forms of lists and dicts and
calls to functions with constant arguments (among which a constant 0.0
and a constant -0.0) -- and more generally when both constants -0.0 and
0.0 appear within the same unit of compilation (expression, function,
...) as for example in:

 def f():
...   a = -0.0
...   return a, 0.0
... 
 f()
(-0.0, -0.0)
 

Why I think it has specifically to do with parsing/compiling, e.g.:

 {23:-0.0, 45:0.0}
{45: -0.0, 23: -0.0}
 x=0.0
 y=-0.0
 {23:x, 45:y}
{45: -0.0, 23: 0.0}
 

so there appears to be no problem once the 0.0 and -0.0 values come from
variables or the like -- only if they're both from constants within the
same unit of compilation.  Indeed, if you put the code above in a
function, rather than in separate entries to the toplevel
interpreter...:

 def g():
...   x = 0.0
...   y = -0.0
...   return {23:x, 45:y}
... 
 g()
{45: 0.0, 23: 0.0}
 

...the bug surfaces again.  Looks a bit like the result of a slightly
errant peephole optimizer pass which tries to roll multiple
occurrences of the same constant within the same codeobject into a
single one, and consider two immutables a multiple occurrence if
they're == to each other (as, indeed, 0.0 and -0.0 must be).

The Python-coded compiler package does NOT give the problem:

 compiler.compile('-0.0,0.0','zap','eval')
code object expression at 0x70068, file zap, line 1
 dis.dis(_)
  1   0 LOAD_CONST   1 (0.0)
  3 UNARY_NEGATIVE  
  4 LOAD_CONST   1 (0.0)
  7 BUILD_TUPLE  2
 10 RETURN_VALUE

...presumably because it doesn't do peephole optimization (nor any other
kind of optimization).

Unfortunately I've never really looked in depth into these parts of
Python so I can't help much; however, if you open a bug at
http://sourceforge.net/tracker/?group_id=5470 I think you stand a good
chance of eventually seeing it fixed in 2.5.x for some x.
Python/peephole.c does appear to be taking some care in constant
folding:

192 case UNARY_NEGATIVE:
193 /* Preserve the sign of -0.0 */
194 if (PyObject_IsTrue(v) == 1)
195 newconst = PyNumber_Negative(v);

so I suspect the problem is elsewhere, but I can't find it yet.


Alex


In the meantime, I hope that some available workarounds for the bug are
clear from this discussion: avoid using multiple constants in a single
compilation unit where one is 0.0 and another is -0.0, or, if you really
can't avoid that, perhaps use compiler.compile to explicitly build the
bytecode you need.

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


Re: Need help in using mod_python

2007-03-11 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 
 
 Hi,
 
 I am trying to setup Apache with Trac which uses mod_python. I get the
 following error:
 
 assert have_pysqlite  0
 
 And I have verify this  via command line as well, that seem no
 problem.

(snip)

What do you get using tracd (the standalone server) ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 1:21 pm, Duncan Booth [EMAIL PROTECTED] wrote:
 Tim Peters wrote inhttp://blog.gmane.org/gmane.comp.python.devel/day=20050409:

  All Python behavior in the presence of a NaN, infinity, or signed zero
  is a platform-dependent accident.  This is because C89 has no such
  concepts, and Python is written to the C89 standard.  It's not easy to
  fix across all platforms (because there is no portable way to do so in
  standard C), although it may be reasonably easy to fix if all anyone
  cares about is gcc and MSVC (every platform C compiler has its own set
  of gimmicks for dealing with these things).

Understood. Platform dependent is fine.  But does this really excuse
results
like the following?

 from math import atan2
 x = -0.; print atan2(0., -1.)
-3.14159265359
 print atan2(0., -1.)
3.14159265359

Mark

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Duncan Booth [EMAIL PROTECTED] wrote:

 Mark Dickinson [EMAIL PROTECTED] wrote:
 
  I guess what's happening is that there's some optimization that avoids
  creating two separate float objects for a float literal that appears
  twice, and that optimization doesn't see the difference between 0. and
  -0. 
 
 Don't guess. Test.
 
  def f():
   x = 0.0
   y = -0.0
   return x, y
 
  dis.dis(f)
   2   0 LOAD_CONST   1 (0.0)
   3 STORE_FAST   0 (x)
 
   3   6 LOAD_CONST   1 (0.0)
   9 STORE_FAST   1 (y)
 
   4  12 LOAD_FAST0 (x)
  15 LOAD_FAST1 (y)
  18 BUILD_TUPLE  2
  21 RETURN_VALUE
 
 Yes. Just the one constant there.

And yet, as I wrote in a parallel post (the result of quite some
exploration), Python/peephole.c takes specific precautions against
improperly constant folding for the unary-minus of 0.0 -- the
collapsing of 0.0 and -0.0 into the same constant must happen
elsewhere (I haven't found out where, yet) and doesn't happen in the
Python-coded compiler module.  So (on platforms where the underlying C
libraries do the right thing) I think this specific overzealous
constant folding must be considered a small bug -- and should be easy
to fix (by specialcasing -0.0 like Python/peephole.c does) if I could
but find out where in the Python sources the folding is happening...


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


Re: threading and iterator crashing interpreter

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 11:35:58 -0300, Janto Dreijer [EMAIL PROTECTED]  
escribió:

 At least, the problem of using the same generator from different threads
 still remains, if you don't use my modified code. In general, when using
 multiple threads you always need some way to syncronize access to shared
 objects. You are lucky with Sessions because append is an atomic  
 operation
 on lists; for more information see   
 http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-threa...

 Again you're right. But even putting a try-except:return around the
 random.choice still manages to break the interpreter. I'm not looking
 for any meaningful output really. I just want it not to break.

A try/except won't help a concurrency problem, unfortunately.

 Like I said, this is just watered down code to try and isolate the
 problem.

So I suggest to start with some small, *correct*, code, and then add more  
features until you reconstruct your big program in a safe way.

-- 
Gabriel Genellina

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 1:26 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
 [Long analysis of probable cause of the problem]

Thank you for this.  I was suspecting something along these lines,
but I don't yet know my way around the source well enough to figure
out where the problem was coming from.

 In the meantime, I hope that some available workarounds for the bug are
 clear from this discussion: avoid using multiple constants in a single
 compilation unit where one is 0.0 and another is -0.0, or, if you really
 can't avoid that, perhaps use compiler.compile to explicitly build the
 bytecode you need.

Yup: the workaround seems to be as simple as replacing all occurrences
of -0.0 with -(0.0).  I'm embarrassed that I didn't figure this out
sooner.

 x, y = -(0.0), 0.0
 x, y
(-0.0, 0.0)

Mark

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread jim-on-linux

#

 Interesting.  So on Windows there's probably no
 hope of what I want to do working.
 But on a platform where the C library does the
 right thing with signed zeros, this
 behaviour is still a little surprising.  I
 guess what's happening is that there's
 some optimization that avoids creating two
 separate float objects for a float literal
 that appears twice, and that optimization
 doesn't see the difference between 0. and -0.

  x, y = 0., -0.
  id(x) == id(y)

 True

 jim-on-linux's solution works in the
 interpreter, but not in a script, presumably
 because we've got file-wide optimization rather
 than line-by-line optimization.

 #test.py
 x = -0.0
 y = 0.0
 print x, y
 #end test.py

  import test

 -0.0 -0.0

 Mark


This is the only way I could make this work in a 
script.

from decimal import Decimal

x = Decimal( -0.0)
y= Decimal(0.0)
print x,y


x = Decimal( 0.0)
y= Decimal(-0.0)
print x,y



jim-on-linux
http:\\www.inqvista.com












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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Mark Dickinson [EMAIL PROTECTED] wrote:

 On Mar 11, 1:26 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
  [Long analysis of probable cause of the problem]
 
 Thank you for this.  I was suspecting something along these lines,
 but I don't yet know my way around the source well enough to figure
 out where the problem was coming from.

The parser/compiler/etc are unfortunately some of the hardest parts of
the sources -- I'm not all that familiar with that part myself, which is
why it took me quite some digging.


  In the meantime, I hope that some available workarounds for the bug are
  clear from this discussion: avoid using multiple constants in a single
  compilation unit where one is 0.0 and another is -0.0, or, if you really
  can't avoid that, perhaps use compiler.compile to explicitly build the
  bytecode you need.
 
 Yup: the workaround seems to be as simple as replacing all occurrences
 of -0.0 with -(0.0).  I'm embarrassed that I didn't figure this out
 sooner.
 
  x, y = -(0.0), 0.0
  x, y
 (-0.0, 0.0)

Glad it works for you, but it's the kind of workaround that could break
with any minor tweak/optimization to the compiler... very fragile:-(.

I think i found the cause of the bug, BTW.  The collection of constants
in a code object is built in Python/compile.c and it's built as a
dictionary, field u_consts in struct compiler_unit.  The visitor for
an expression that is a number is (in a case statement)

case Num_kind:
ADDOP_O(c, LOAD_CONST, e-v.Num.n, consts);
break;

(line 2947 of compile.c in Python's current sources from svn). ADDOP_O
just calls compiler_addop_o, which in turn does compiler_add_o before
adding the opcode (LOAD_CONST)

compiler_add_o (at lines 903-933) is used for all of the temporary
dictionaries in compiler_unit; a Python equivalent, basically, would be:

def eqv_cao(somedict, someobj):
# make sure types aren't coerced, e.g. int and long
t = someobj, type(someobj)
if t in somedict:
return somedict[t]
somedict[t] = index = len(somedict)
return index

a simple and fast way to provide a distinct numeric index (0 and up) to
each of a bunch of (hashable) objects.

Alas, here is the problem...: 0.0 and -0.0 are NOT separate as dict
keys!  They are == to each other.  So are 0, 0L, and 0+j0, but the
compiler smartly distinguishes these cases by using (obj, type) as the
key (the *types* are distinguished, even though the *values*) are; this
doesn't help with 0.0 and -0.0 since both have type float.

So, the first occurrence of either 0.0 or -0.0 in the compilation unit
ends up in the table of constants, and every other occurrence of either
value later in the unit is mapped to that one constant value:-(

This is not trivial to fix cleanly...:-(.  compiler_add_o would have to
test is the object I'm storing -0.0 (I don't even know how to do that
in portable C...) and then do some kludge -- e.g. use as the key into
the dict (-0.0, 0) instead of (-0.0, float) for this one special case.
(I think the table of constants would still be emitted OK, since the
type part of the key is elided anyway in that table as placed in the
bytecode).  Or maybe we should give up ever storing -0.0 in the tables
of constant and ALWAYS have 0.0, unary-minus wherever it appears (that
would presumably require working on the AST-to-bytecode visitors that
currently work ever-so-slightly-differently for this specific
troublespot in the C-coded version vs the Python-coded one...).

If you know the proper way to test for -0.0 in portable C code (or some
feature macro to use in a #if to protect nonportable code) I could try
proposing the first of these two solutions as a patch (I'm not going to
keep delving into that AST and visitors much longer...:-), but I suspect
it would be rejected as too tricky [and minisculely slowing down every
compilation] for something that's too much of special case [and Python
does not undertake to support in general anyway].  Still, we can't be
sure unless we try (and maybe somebody can think of a cleaner
workaround...).


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


Re: number generator

2007-03-11 Thread Army1987

cesco [EMAIL PROTECTED] ha scritto nel messaggio 
news:[EMAIL PROTECTED]
I have to generate a list of N random numbers (integer) whose sum is
 equal to M. If, for example, I have to generate 5 random numbers whose
 sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
 simple pattern or function in Python to accomplish that?

 Thanks and regards
 Francesco


You can initialize a list to [1, 1, 1, 1, 1], and generate 45 random 
integers between 1 and 5, and every time a number is generated, increase the 
Nth number in the list by one.

Not all distinct lists will have the same chance of occurring, e.g. [46, 1, 
1, 1, 1] will be much less likely than [10, 10, 10, 10, 10]. Depending on 
what you need these numbers for, it can be a good thing or a bad thing.

--Army1987


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


Putting Metaclasses to Work

2007-03-11 Thread Alan Isaac
Forman's book is out of print.
Is there a good substitute?

Thanks,
Alan Isaac


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


Re: Need help in using mod_python

2007-03-11 Thread [EMAIL PROTECTED]
On Mar 11, 1:02 pm, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] a écrit :



  Hi,

  I am trying to setup Apache with Trac which uses mod_python. I get the
  following error:

  assert have_pysqlite  0

  And I have verify this  via command line as well, that seem no
  problem.

 (snip)

 What do you get using tracd (the standalone server) ?

I am using apache with mod_python.

I have done a sanity check with command prompt, it can find
'pysqlite',
But when I access Trac using Apache (via mod_python), it somehow can't
find 'pysqlite' and gives me an error.

So my question is how python command prompt loads library differently
from mod_python?

 # python
Python 2.3.4 (#1, Feb  2 2005, 11:44:49)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type help, copyright, credits or license for more information.

 import trac.db.sqlite_backend
 trac.db.sqlite_backend._ver
(3, 3, 13)
 trac.db.sqlite_backend.have_pysqlite
2
 trac.db.sqlite_backend.sqlite.version

'2.3.3'

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

Re: Python in a Nutshell v2.5 shortcomings

2007-03-11 Thread Alex Martelli
Bjoern Schliessmann [EMAIL PROTECTED]
wrote:

 Alex Martelli wrote:
 
  I do know that the 2nd edition of Python in a Nutshell tries to do
  so, but falls quite a bit short on a number of important new
  additions to the library
 
 Which, if I may ask?

For example, all I say about ctypes is that it's scheduled to be added
to the standard library in Python 2.5, plus the URL to theller's pages
on it; it's surely worth at least the 5 pages I devoted to covering
Pyrex (considering that the latter is not in the standard library), not
just 5 lines:-(.  Similarly, ElementTree is essentially just mentioned,
not really covered (while it would deserve the 10-12 pages that I
instead used to cover minidom), and SQLite gets less than a page
(probably enough for elementary use, since the DBAPI _is_ well covered,
but 2-3 pages with advanced issues and a relatively long examples would
have been better).

You could say, for 2.5 coverage, the book is missing about 20 pages it
should have -- not all that much, in comparison to the 700 pages it does
have, but not ideal (as for the new compiler stuff -- modules
compiler, parser, symbol, etc -- I'm not even sure how long it would
take to do them justice... perhaps another 20-30 pages... but perhaps
those subjects are a bit too exoteric to keep expanding the book!-).


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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Alex Martelli [EMAIL PROTECTED] wrote:
   ...
  Yup: the workaround seems to be as simple as replacing all occurrences
  of -0.0 with -(0.0).  I'm embarrassed that I didn't figure this out
  sooner.
  
   x, y = -(0.0), 0.0
   x, y
  (-0.0, 0.0)
 
 Glad it works for you, but it's the kind of workaround that could break
 with any minor tweak/optimization to the compiler... very fragile:-(.

OTOH, Python 2.4 works just fine...:

Python 2.4.3 (#1, Apr  7 2006, 10:54:33) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type help, copyright, credits or license for more information.
 0.0,-0.0
(0.0, -0.0)
 -0.0,0.0
(-0.0, 0.0)

so it seems to be very specifically a 2.5 problem.


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


Re: any better code to initalize a list of lists?

2007-03-11 Thread Donald Fredkin
John wrote:

 For my code of radix sort, I need to initialize 256 buckets. My code
 looks a little clumsy:
 
 radix=[[]]
 for i in range(255):
radix.append([])
 
 any better code to initalize this list?

radix = [[[]]*256][0]

-- 

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


Re: any better code to initalize a list of lists?

2007-03-11 Thread Stargaming
Donald Fredkin schrieb:
 John wrote:
 
 
For my code of radix sort, I need to initialize 256 buckets. My code
looks a little clumsy:

radix=[[]]
for i in range(255):
   radix.append([])

any better code to initalize this list?
 
 
 radix = [[[]]*256][0]
 

  x = [[[]]*256][0]
  x
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], 
[], [], ...
  x[0].append(1)
  x
[[1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], 
[1], [1], ...

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


Re: any better code to initalize a list of lists?

2007-03-11 Thread Bart Willems
Donald Fredkin wrote:
 John wrote:
 
 For my code of radix sort, I need to initialize 256 buckets. My code
 looks a little clumsy:

 radix=[[]]
 for i in range(255):
radix.append([])

 any better code to initalize this list?
 
 radix = [[[]]*256][0]
 

No I fell for that one too - it's the same as 'radix = [[]] * 256. Try 
radix[0].append('dead parrot')..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Scott David Daniels
Alex Martelli wrote:
 Alas, here is the problem...: 0.0 and -0.0 are NOT separate as dict
 keys!  They are == to each other.  So are 0, 0L, and 0+j0, but the
 compiler smartly distinguishes these cases by using (obj, type) as the
 key (the *types* are distinguished, even though the *values*) are; this
 doesn't help with 0.0 and -0.0 since both have type float
 If you know the proper way to test for -0.0 in portable C code (or some
 feature macro to use in a #if to protect nonportable code) 

Perhaps you could add a type NegativeFloat -- a subtype of float,
and distinguish negative zero from zero that way.  Not saying I know how
in portable C, but 

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-11 Thread Alex Martelli
Army1987 [EMAIL PROTECTED] wrote:

 cesco [EMAIL PROTECTED] ha scritto nel messaggio 
 news:[EMAIL PROTECTED]
 I have to generate a list of N random numbers (integer) whose sum is
  equal to M. If, for example, I have to generate 5 random numbers whose
  sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
  simple pattern or function in Python to accomplish that?
 
  Thanks and regards
  Francesco
 
 
 You can initialize a list to [1, 1, 1, 1, 1], and generate 45 random 
 integers between 1 and 5, and every time a number is generated, increase the
 Nth number in the list by one.
 
 Not all distinct lists will have the same chance of occurring, e.g. [46, 1,
 1, 1, 1] will be much less likely than [10, 10, 10, 10, 10]. Depending on
 what you need these numbers for, it can be a good thing or a bad thing.

And a1-liner way to get the numbers (net of the mandatory +1 for each)
is:

  map([random.randrange(5) for i in xrange(45)].count, xrange(5))

i.e., this gives 5 integers (each between 0 and 45 included) summing to
45 -- add 1 to each of them to get the desired result.

Without any specification regarding the distributions required for the
5 random numbers it's really impossible to say whether these are
better or worse than other proposed solutions.


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


Watching a file another app is writing

2007-03-11 Thread Gordon Airporte
I'm trying to find a way to take a file that another program has opened 
and writes to periodically, open it simultaneously in Python, and 
automatically update some of my objects in Python when the file is 
written to.
I can open the file and manually readlines() from it to keep up to date, 
it's the automatic part I'm having trouble with. This is on Windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Gabriel Genellina
En Sun, 11 Mar 2007 15:26:01 -0300, Alex Martelli [EMAIL PROTECTED] escribió:

 Or maybe we should give up ever storing -0.0 in the tables
 of constant and ALWAYS have 0.0, unary-minus wherever it appears (that
 would presumably require working on the AST-to-bytecode visitors that
 currently work ever-so-slightly-differently for this specific
 troublespot in the C-coded version vs the Python-coded one...).

I think that way is the less intrusive, doesn't rely on a particular FP  
implementation, and the more likely to be accepted.
Looking at ast.c, the culprit is some optimization in ast_for_factor, line  
1506
 /* If the unary - operator is applied to a constant, don't generate
a UNARY_NEGATIVE opcode.  Just store the approriate value as a
constant.  The peephole optimizer already does something like
this but it doesn't handle the case where the constant is
(sys.maxint - 1).  In that case, we want a PyIntObject, not a
PyLongObject.
 */

After the long if, I would use parsenumber(STR(pnum)) and check the type  
and value of the resulting object; if it's a float and 0.0, skip the  
optimization and continue below as a normal case.
Unfortunately I'm not able to compile and test the code right now, so I  
can't provide an actual patch. (At least, not until tuesday). But I hope  
this simple comment is useful anyway...

(I cannot find peephole.c on the source distribution for Python 2.5, but  
you menctioned it on a previous message, and the comment above refers to  
the peephole optimizer... where is it?)

-- 
Gabriel Genellina

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 2:59 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
 [...]
 OTOH, Python 2.4 works just fine...:

 Python 2.4.3 (#1, Apr  7 2006, 10:54:33)
 [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
 Type help, copyright, credits or license for more information. 
 0.0,-0.0
 (0.0, -0.0)
  -0.0,0.0

 (-0.0, 0.0)

 so it seems to be very specifically a 2.5 problem.

I've filed a bug report (bug #1678380) and got an impressively
quick response from MvL.  It looks like this is a `won't fix'.
Oh well.

Thanks for all your help.

Mark

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


Re: Need help in using mod_python

2007-03-11 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 On Mar 11, 1:02 pm, Bruno Desthuilliers
 [EMAIL PROTECTED] wrote:
 
[EMAIL PROTECTED] a écrit :




Hi,

I am trying to setup Apache with Trac which uses mod_python. I get the
following error:

assert have_pysqlite  0

And I have verify this  via command line as well, that seem no
problem.

(snip)

What do you get using tracd (the standalone server) ?
 
 
 I am using apache with mod_python.

You're trying to, yes. But what *I*'m asking *you* is what you get using 
tracd.

 I have done a sanity check with command prompt,

using your account's env

 it can find
 'pysqlite',
 But when I access Trac using Apache (via mod_python),

which uses a somewhat different (and very restricted) env...

 it somehow can't
 find 'pysqlite' and gives me an error.
 
 So my question is how python command prompt loads library differently
 from mod_python?

I know I'm a little bit dumb, but I had perfectly understood your 
question (which BTW is not posted at the best place - both Trac and 
mod_python have dedicated mailing-lists). Can you imagine that I have 
good reasons to ask you what you get using tracd ?


(re-snip already snipped code)
-- 
http://mail.python.org/mailman/listinfo/python-list


cherrypy sub-process

2007-03-11 Thread Bart Van Loon
Hi all,

I have written a small program in Python which acts as a wrapper around
mpd and natd on a FreeBSD system. It gets the status, restarts the
processes, etc...

Then, I created a tiny cherrypy webapp which provides a webinterface to
this program. All works fine, but for the following problem:

cherrypy listens on port 1234. whenever I browse to that port and invoke
any action that involves (re)starting mpd or natd, which happens with
commands.getstatusoutput() (which uses os.popen()), I cannot restart
cherrypy without killing the mpd and/or natd processes spawned by it in
the previous session, because port 1234 willl still be in use.

lsof -i tcp tells me that it's exactly those mpd and/or natd processes
which are keeping that port 1234 from freeing up after I (succesfully)
kill cherrypy.

Is there any explanation to this, or, even better, a solution?

Thank you very much in advance.

-- 
regards,
BBBart

   To make a bad day worse, spend it wishing for the impossible. -Calvin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Tim Peters
[attribution lost]
...
 Yup: the workaround seems to be as simple as replacing all 
occurrences
 of -0.0 with -(0.0).  I'm embarrassed that I didn't figure this out
 sooner.
 
  x, y = -(0.0), 0.0
  x, y
 (-0.0, 0.0)

[Alex Martelli]
 Glad it works for you, but it's the kind of workaround that could
 break with any minor tweak/optimization to the compiler...
 very fragile:-(.

[also Alex]
 OTOH, Python 2.4 works just fine...:

 Python 2.4.3 (#1, Apr  7 2006, 10:54:33) 
 [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
 Type help, copyright, credits or license for more information.
  0.0,-0.0
 (0.0, -0.0)
  -0.0,0.0
 (-0.0, 0.0)

 so it seems to be very specifically a 2.5 problem.

It's a bug that keeps resurfacing, probably because there's no portable 
way to test that it stays fixed :-( (it's not an accident that the OP 
relied on atan2 to distinguish +0.0 from -0.0!  they act the same in 
/almost/ all contexts).

Python's grammar doesn't have negative numeric literals.  Instead

- CONSTANT_LITERAL

looks like unary minus applied to the non-negative CONSTANT_LITERAL.  
All early versions of Python worked that way too.

The first time the +/- 0.0 bug occurred is when the front end was 
changed to act as if

- CONSTANT_LITERAL

were a literal in its own right, and then that +0.0 == -0.0 caused the 
first instance of either in a compilation unit to be used as the value 
for all instances of both throughout the compilation unit.  That was 
fixed by refusing to apply the optimimization if the value of 
CONSTANT_LITERAL was a float that compared equal to 0.0.

2.5 introduced a new front end and more ambitious constant-folding, and 
I expect the bug showed up again due to one of those.

Note:  printing the value of a float 0 may not reveal its sign.  IIRC, 
glibc's float-to-string routines do display the sign of 0, but 
Microsoft's do not.  However, atan2() is sensitive to the sign under 
both glibm and Microsoft's libm equivalent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Paul Rubin
Tim Peters [EMAIL PROTECTED] writes:
 2.5 introduced a new front end and more ambitious constant-folding, and 
 I expect the bug showed up again due to one of those.

I hope it does get fixed.  Not having referential transparency in a
basic math function like atan2 is pretty disturbing in a modern
computer language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Paul Rubin
Dennis Lee Bieber [EMAIL PROTECTED] writes:
   Pardon? What is the right thing with signed zeros... In the last
 30 years I've been on machines that normalize floating zero into a true
 zero (all bits are zero: mantissa, exponent, and sign). This is the
 first time I've even seen a variable output as a negative 0.0!

Most machines these days use IEEE 754 which supports negative zero.

http://en.wikipedia.org/wiki/Negative_zero
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Mark Dickinson
On Mar 11, 5:15 pm, Tim Peters [EMAIL PROTECTED] wrote:
 It's a bug that keeps resurfacing, probably because there's no
portable
 way to test that it stays fixed :-( (it's not an accident that the OP
 relied on atan2 to distinguish +0.0 from -0.0!  they act the same in
 /almost/ all contexts).

Not an accident, but not a contrived example either.  I'd rewritten
all the cmath routines (in pure Python) to be more numerically aware
and use the
`correct' (= those recommended by Kahan) branch cuts.  It was in
writing the unit tests for this that the problems above surfaced.

By the way, I don't suppose that anybody would be interested in
a rewritten cmath for Python 2.6?  It wouldn't be hard for me to
rewrite what I already have in C, and add suitable documentation
and tests.

Mark

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


Bitpacked Data

2007-03-11 Thread none
i need to interface python with a bitpacked data file,
the structure recorded in the file is the following:

struct {
var_1 4bit
var_2 6bit
var_3 2bit
var_3 4bit
}

how can read the struct and convert data into dictionary

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


Re: a better solution for GUI in python

2007-03-11 Thread Uwe Grauer
ce wrote:
 Hi,
 
 My company is using python currently for our website. We need to
 develop a GUI front-end for our ERP that would be portable (Windows
 and Linux).
 
 My question is which solution would be better for the GUI (and easier
 to implement)? I knew there are something like wxidgets, QT and pyGTK?
 actually we will need some complicated stuff in the GUI and yet I
 don't know much about GUI programming.
 
 Any recommendation guys?
 

Take a look at Dabo.
It is using wxWidgets and runs on Windows, Mac, Linux.
http://www.dabodev.com

Uwe

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


Re: Need help with a string plz! (newbie)

2007-03-11 Thread Grant Edwards
On 2007-03-10, Hendrik van Rooyen [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:

 Oh, thanks for the advice then. And as for Grant..look forward to
 seeing more of your posts.

 YOW! - some recognition at last!

:)

I see somebody pays attention to sigs -- which, BTW, are old quotes
from the Zippy the Pinhead comic strip. www.zippythepinhead.com

-- 
Grant

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


Re: a better solution for GUI in python

2007-03-11 Thread ici
On Mar 11, 1:03 pm, ce [EMAIL PROTECTED] wrote:
 Hi,

 My company is using python currently for our website. We need to
 develop a GUI front-end for our ERP that would be portable (Windows
 and Linux).

 My question is which solution would be better for the GUI (and easier
 to implement)? I knew there are something like wxidgets, QT and pyGTK?
 actually we will need some complicated stuff in the GUI and yet I
 don't know much about GUI programming.

 Any recommendation guys?

http://pythoncard.sourceforge.net/ - Debugger, visual editor(resource
editor) , one place event handlers like on_Object_Command, uses
wxPython but easy than VB.

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


Re: Bitpacked Data

2007-03-11 Thread Bjoern Schliessmann
none wrote:

 i need to interface python with a bitpacked data file,
 the structure recorded in the file is the following:
 
 struct {
 var_1 4bit
 var_2 6bit
 var_3 2bit
 var_3 4bit
 }

Strange data types. What language is this?
 
 how can read the struct and convert data into dictionary

I'd use the module struct, with bit shifting operators to extract
the bits.


Regards,


Björn

-- 
BOFH excuse #232:

Ionization from the air-conditioning

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Paul Rubin
Mark Dickinson [EMAIL PROTECTED] writes:
 By the way, I don't suppose that anybody would be interested in
 a rewritten cmath for Python 2.6?  It wouldn't be hard for me to
 rewrite what I already have in C, and add suitable documentation
 and tests.

I can't speak for the developers but my personal opinion is that this
is worthwhile.  I'm pretty Common Lisp and Scheme specify the branch
cuts and I believe Java does the same.  That is to help with the
consistency and predicability of program behavior as well as to help
various numerical algorithms.  C has a different goal, which is to be
a semi-portable assembly language, putting priority instead on
minimizing intermediation between the programmer and the machine,
instead of on predicability.  Python should take the approach of the
higher level languages and implement this stuff precisely, instead of
just going along with whatever loose semantics the underlying C
implementation happens to supply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Paddy
On Mar 11, 9:28 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
 Dennis Lee Bieber [EMAIL PROTECTED] writes:

 Pardon? What is the right thing with signed zeros... In the last
  30 years I've been on machines that normalize floating zero into a true
  zero (all bits are zero: mantissa, exponent, and sign). This is the
  first time I've even seen a variable output as a negative 0.0!

 Most machines these days use IEEE 754 which supports negative zero.

 http://en.wikipedia.org/wiki/Negative_zero

Isn't negative zero mathematically the same as zero? Isn't -0 just an
artefact of the representation of floating point numbers? Shouldn't
f(0) == f(-0) for all functions f?
I read the wikipedia article about meteorologists using -0 to denote a
negative number rounded to zero for the purposes of binning, i.e. if
you want to tally days with temperature above and below zero, but it
doesn't seem right. You should arrange for any temperature to be in
only one range and record temperatures to their determined accuracy. a
temperature of zero would only be in one bin and if a temperature is
read as -0.2 and th rounding says it should be taken as zero then it
should go in the same bin as any positive reading that is rounded to
zero.
Getting back to Python, shouldn't we strive to remove any distinction?
a zero is a zero regardless of sign and a function like atan returning
one of two different vaues for an argument of zero is actually
mathematically not a bad thing to do?

- Paddy.

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Michael Spencer
Gabriel Genellina wrote:

 
 (I cannot find peephole.c on the source distribution for Python 2.5, but  
 you menctioned it on a previous message, and the comment above refers to  
 the peephole optimizer... where is it?)
 

The peephole optimizer is in compile.c - the entry point is optimize_code

BTW, I have written a pure-Python compiler which aims to be functionally 
identical to the Python 2.5 compiler, and is in fact very similar (much closer 
than stdlib.compiler).  It may be helpful in investigating alternative 
workarounds for the -0.0 issue.

http://svn.brownspencer.com/pycompiler/branches/new_ast/

Michael

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


Re: war with china? a different approach?

2007-03-11 Thread rebeccagcox
Are you there, cause I don't want to waste my time writing a response
to that if you're not there anymore. Please respond w/ a new post if
you do check this.


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


Re: Phase change material ...

2007-03-11 Thread rebeccagcox
Hey, thermate--could you check your post on China from January and
respond. Thanks.

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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Paul Rubin
Paddy [EMAIL PROTECTED] writes:
  Most machines these days use IEEE 754 which supports negative zero.
  http://en.wikipedia.org/wiki/Negative_zero
 
 Isn't negative zero mathematically the same as zero? Isn't -0 just an
 artefact of the representation of floating point numbers? Shouldn't
 f(0) == f(-0) for all functions f?

Not sure what you mean.  Floating point numbers and in particular
IEEE 754 floating point numbers are a set of values and operations
with particular characteristics, that computers happen to implement.
They are not the same thing as the mathematical real numbers.  For
example, there are infinitely many real numbers, but there are only
finitely many 64-bit IEEE floating point numbers (at most 2**64 of
them).  They don't satisfy the same algebraic laws as real numbers.
For example, (1e100 + 1) == 1e100, and as a consequence, (1e100 + 1) -
1e100 == 0, but (1e100 - 1e100) + 1 == 1, so the commutative addition
law doesn't hold.  These are all part of a mesh of interlocking
compromises made in floating point computer arithmetic to approximate
real-number arithmetic with finite-precision values.  At first (i.e.
from the early computer era through the 1970's or so) this stuff was
designed somewhat ad hoc by computer architects, but eventually
serious numerical mathemticians got into the act, figuring out how to
make the best possible choices of these compromises for numerical
computation.  The result was IEEE 754, which resulted in Prof. Kahan
winning the Turing award in 1989.

IEEE 754 specifies that -0 and +0 are separate numbers.  Yes it is an
artifact in the sense of being one of the compromises.  But these
compromises all interact with each other to make the errors cancel in
various numerical algorithms.  The existence of -0 in IEEE 754 is part
of an intricate framework designed very carefully over a long period
by extremely experienced and knowledgeable people who knew what they
were doing.  It's not really wise to mess with it unless you're
planning to undertake a project to redesign computer arithmetic of
similar scope to the IEEE 754 effort.

 Getting back to Python, shouldn't we strive to remove any distinction?
 a zero is a zero regardless of sign and a function like atan returning
 one of two different vaues for an argument of zero is actually
 mathematically not a bad thing to do?

No.  Floating point numbers are not the same as real numbers and they
don't satisfy the same laws.  There have been some proposals
(rejected) for Python to support exact rational arithmetic in addition
to floating point and exact integer arithmetic.  Exact rationals in
Python (if implemented) should behave like mathematical rationals.
But Python floating point arithmetic should follow IEEE 754, at least
when the hardware supports it, which these days is almost always.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread André
On Mar 11, 7:49 pm, Paddy [EMAIL PROTECTED] wrote:

 Isn't negative zero mathematically the same as zero? Isn't -0 just an
 artefact of the representation of floating point numbers? Shouldn't
 f(0) == f(-0) for all functions f?

Read the original post again...  The relevant part is:

I'm working in a situation
involving complex arithmetic where branch cuts, and hence signed
zeros, are important, and it would be handy if the above code could be
relied upon to do the right thing.


You may want to read about branch cuts and complex arithmetics.  I
don't mean this as a putdown - simply as a useful suggestion for you
to read.

André



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

Re: Bitpacked Data

2007-03-11 Thread bearophileHUGS
Bjoern Schliessmann:
 I'd use the module struct, with bit shifting operators to extract
 the bits.

Maybe Pyrex can be used to create a small module that can manage
similar bitfields quickly and with a syntax not too much far from the
Erlang bit syntax.

Bye,
bearophile

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


Weekly Python Patch/Bug Summary

2007-03-11 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  380 open (-36) /  3658 closed (+65) /  4038 total (+29)
Bugs:  965 open ( -9) /  6555 closed (+35) /  7520 total (+26)
RFE :  272 open ( +4) /   253 closed ( +2) /   525 total ( +6)

New / Reopened Patches
__

Extension documentation for subclasses  (2007-03-01)
CLOSED http://python.org/sf/1671450  opened by  Pete Shinners

MultiCall bug crashing the config dialog  (2007-03-02)
CLOSED http://python.org/sf/1672481  opened by  Tal Einat

urllib2 requests history + HEAD support  (2007-03-03)
   http://python.org/sf/1673007  opened by  KDanilov aka koder

README update: Bash default on ac OS X  (2007-03-03)
CLOSED http://python.org/sf/1673121  opened by  Witten

Mac OS X: libtool  (2007-03-03)
   http://python.org/sf/1673122  opened by  Witten

change repr(...) from 'Ellipsis' to '...'  (2007-03-04)
CLOSED http://python.org/sf/1673355  opened by  John Reese

Identify modules to be built and not built  (2007-03-04)
CLOSED http://python.org/sf/1673619  opened by  Skip Montanaro

'G' formatting doesn't catch same errors as 'g'  (2007-03-04)
   http://python.org/sf/1673759  opened by  Eric V. Smith

Identify modules which couldn't be built  (2007-03-04)
CLOSED http://python.org/sf/1673619  reopened by  loewis

sq_ass_slice ignored if  sq_slice not defined  (2007-03-05)
CLOSED http://python.org/sf/1674228  opened by  ?iga Seilnacht

Epoll wrapper  (2007-03-06)
   http://python.org/sf/1675118  opened by  TH

Draft implementation for PEP 364  (2007-03-06)
   http://python.org/sf/1675334  opened by  Barry A. Warsaw

PEP 3114 -- next() - __next__()  (2007-03-07)
   http://python.org/sf/1675363  opened by  Georg Brandl

Make PyComplex_AsCComplex use __complex__  (2007-03-07)
   http://python.org/sf/1675423  opened by  Mark Dickinson

Zipfile tweaks and test coverage improvement  (2007-03-06)
   http://python.org/sf/1675424  opened by  Alan McIntyre

Use getaddrinfo() in urllib2.py for IPv6 support  (2007-03-07)
   http://python.org/sf/1675455  opened by  David Cantrell

Refactor test_pty.py to use unittest.  (2007-03-06)
CLOSED http://python.org/sf/1675471  opened by  Jerry Seutter

[gzip] Performance for small reads and fix seek problem  (2007-03-07)
   http://python.org/sf/1675951  opened by  Florian Festi

Remove dead code in typeobject's type_new()  (2007-03-07)
CLOSED http://python.org/sf/1675981  opened by  ?iga Seilnacht

Remove trailing slash from --prefix  (2007-03-07)
   http://python.org/sf/1676135  opened by  Björn Lindqvist

New File I/O type for Python 3000, plus .h and unit tests  (2007-02-28)
CLOSED http://python.org/sf/1671314  reopened by  collinwinter

Add a PeriodicTimer to threading  (2007-03-08)
   http://python.org/sf/1676820  opened by  Björn Lindqvist

Adding timeout to socket.py and httplib.py  (2007-03-08)
   http://python.org/sf/1676823  opened by  Facundo Batista

Refactor test_popen2.py to use unittest.  (2007-03-08)
   http://python.org/sf/1676994  opened by  Jerry Seutter

Support CREATE_SUSPENDED flag in subprocess.py for Win32  (2007-03-09)
   http://python.org/sf/1677688  opened by  Chris Heller

site.py small ?bug fix | change?  (2007-03-10)
   http://python.org/sf/1677862  opened by  KDanilov aka koder

Efficient reverse line iterator   (2007-03-10)
   http://python.org/sf/1677872  opened by  Mark Russell

Removal of Tuple Parameter Unpacking [PEP3113]  (2007-03-10)
   http://python.org/sf/1678060  opened by  Tony Lownds

improve telnetlib.Telnet so option negotiation becomes easie  (2007-03-10)
   http://python.org/sf/1678077  opened by  Björn Lindqvist

Refactor test_operations.py to use unittest.  (2007-03-10)
   http://python.org/sf/1678088  opened by  Jerry Seutter

Adding a testcase for the bug in find_longest_match  (2007-03-11)
   http://python.org/sf/1678339  opened by  Denys Rtveliashvili

A fix for the bug #1528074 [warning: quite slow]  (2007-03-11)
   http://python.org/sf/1678345  opened by  Denys Rtveliashvili

Patches Closed
__

Extension documentation for subclasses  (2007-03-01)
   http://python.org/sf/1671450  closed by  gbrandl

MultiCall bug crashing the config dialog  (2007-03-02)
   http://python.org/sf/1672481  closed by  gbrandl

README update: Bash default on Mac OS X  (2007-03-03)
   http://python.org/sf/1673121  closed by  gbrandl

change repr(...) from 'Ellipsis' to '...'  (2007-03-04)
   http://python.org/sf/1673355  closed by  gvanrossum

Use a set to keep interned strings  (2006-06-16)
   http://python.org/sf/1507011  closed by  loewis

Add support for the If-Modified-Since header  (2006-03-04)
   http://python.org/sf/1442867  closed by  loewis

N-d array interface for array object  (2006-03-18)
   http://python.org/sf/1452906  closed by  loewis

Fix for win32 proxy bypass support (no_proxy) in urllib(2)  (2005-03-01)
   

Object instance reporting to a container class instance

2007-03-11 Thread Daniel Lipovetsky
I would like for an object to report to a container object when a
new instance is created or deleted. I could have a container object
that is called when a new instance is created, as below.

class AnyObject:
pass

class Container:
links = []
def add(self,other):
while other not in self.links:
self.links.append(other)
def rem(self,other):
while other in self.links:
self.links.remove(other)
...

container = Container()
a = AnyObject()
container.add(a)

My question is: can (should? :-) this reporting be done inside the
instance's __init__ and __del__ methods (that is, an instance
reports to the container as soon as it is created or deleted)?

Thanks!
Daniel

---

I'm working out a design where Object A is linked to Object B, and
both objects become aware of that relationship. I have implemented an
example successfully; the code is below. My main question is above,
but I would appreciate comments on the code! (For example, I'm
wondering whether my way of defining variables in the class but
assigning them locally to each instance (in the Object.init method)
is really a bad kludge...)


class Object():
def __del__(self):
print buh-bye!, self # Verbose for understanding garbage cleanup
def init(self,name):
self.links = []
self.name = name
def add(self,other):
while other not in self.links:
self.links.append(other)
other.add(self)
def rem(self,other):
while other in self.links:
self.links.remove(other)
other.rem(self)

class Student(Object):
def __init__(self,name):
self.init(name)

class Section(Object):
def __init__(self,name):
self.init(name)

class Task(Object):
def __init__(self,name):
self.init(name)

## Construct test instances!

students = {}
for name in ['Jose','Daniel','Rusty']:
student = Student(name)
students[name] = student

sections = {}
for name in ['English 1']:
section = Section(name)
sections[name] = section

tasks = {}
for name in ['Homework 1','Exam 1','Homework 2','Exam 2']:
task = Task(name)
tasks[name] = task

# Display example connections
def show_connections():
for section in sections:
print sections[section].name
for link in sections[section].links:
print \t, link.name

# Add some connections...

print Now adding connections...
for name in tasks:
sections['English 1'].add(tasks[name])
show_connections()

# Remove some connections...

print Now removing connections...
for name in tasks:
sections['English 1'].rem(tasks[name])
show_connections()

for task in tasks:
print tasks[task].links

for section in sections:
print sections[section].links

## Test garbage cleanup

sections['English 1'].add(tasks['Exam 1'])
print sections['English 1'].links
sections['English 1'].rem(tasks['Exam 1'])
del sections['English 1']
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Gabriel Genellina [EMAIL PROTECTED] wrote:

 En Sun, 11 Mar 2007 15:26:01 -0300, Alex Martelli [EMAIL PROTECTED] 
 escribió:
 
  Or maybe we should give up ever storing -0.0 in the tables
  of constant and ALWAYS have 0.0, unary-minus wherever it appears (that
  would presumably require working on the AST-to-bytecode visitors that
  currently work ever-so-slightly-differently for this specific
  troublespot in the C-coded version vs the Python-coded one...).
 
 I think that way is the less intrusive, doesn't rely on a particular FP
 implementation, and the more likely to be accepted.
 Looking at ast.c, the culprit is some optimization in ast_for_factor, line
 1506
  /* If the unary - operator is applied to a constant, don't generate
 a UNARY_NEGATIVE opcode.  Just store the approriate value as a
 constant.  The peephole optimizer already does something like
 this but it doesn't handle the case where the constant is
 (sys.maxint - 1).  In that case, we want a PyIntObject, not a
 PyLongObject.
  */
 
 After the long if, I would use parsenumber(STR(pnum)) and check the type
 and value of the resulting object; if it's a float and 0.0, skip the
 optimization and continue below as a normal case.
 Unfortunately I'm not able to compile and test the code right now, so I
 can't provide an actual patch. (At least, not until tuesday). But I hope
 this simple comment is useful anyway...

Yep, it sure might, if I can make time to act on it:-).


 (I cannot find peephole.c on the source distribution for Python 2.5, but
 you menctioned it on a previous message, and the comment above refers to
 the peephole optimizer... where is it?)

http://svn.python.org/view/python/trunk/Python/peephole.c?rev=54086view
=auto

to browse the current version on the trunk.  Right under the Python
toplevel subdirectory in the sources, IOW.


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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Alex Martelli [EMAIL PROTECTED] wrote:
   ...
 Yep, it sure might, if I can make time to act on it:-).

...and I did -- patch 1678668 is right there, brand newm at
http://sourceforge.net/tracker/index.php .

I hope it also satisfies the timbot's very reasonable lament about the
bug resurfacing once in a while, since it included one more unittest to
check whether the bug is there (TDD rocks!-). 


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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Mark Dickinson [EMAIL PROTECTED] wrote:

 On Mar 11, 2:59 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
  [...]
  OTOH, Python 2.4 works just fine...:
 
  Python 2.4.3 (#1, Apr  7 2006, 10:54:33) [GCC 4.0.1 (Apple Computer,
  Inc. build 5250)] on darwin Type help, copyright, credits or
  license for more information. 0.0,-0.0
  (0.0, -0.0)
   -0.0,0.0
 
  (-0.0, 0.0)
 
  so it seems to be very specifically a 2.5 problem.
 
 I've filed a bug report (bug #1678380) and got an impressively
 quick response from MvL.  It looks like this is a `won't fix'.
 Oh well.

That bug isn't formally closed yet, and the discussion's going on, we'll
see.  Meanwhile can you try my patch 1678668 just to double check it
does fix everything?  (It's agains the current HEAD of Python's svn).


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


Re: Signed zeros: is this a bug?

2007-03-11 Thread Alex Martelli
Tim Peters [EMAIL PROTECTED] wrote:
   ...
 It's a bug that keeps resurfacing, probably because there's no portable
 way to test that it stays fixed :-( (it's not an accident that the OP
 relied on atan2 to distinguish +0.0 from -0.0!  they act the same in 

Please take a look at my patch 1678668, brand new at
http://sourceforge.net/tracker/index.php and as yet unassigned (hint,
hint:-).

I hope it satisfies your very reasonable lament about the bug
resurfacing once in a while, since it included one more unittest to
check whether the bug is there (TDD rocks!-), based exactly on the
behavior of atan2 (only on IEEE-format machines, though).

 2.5 introduced a new front end and more ambitious constant-folding, and
 I expect the bug showed up again due to one of those.

Yep, in ast.c's ast_for_factor -- it lacks the specialcasing that
peephole.c does have (and my patch essentially adds it back).

If it's worth specialcasing in peephole.c (and I strongly agree with
Raymond's implicit opinion that it is), it should be just as worth
specialcasing in ast.c, no?-)


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


  1   2   >