Front Range Pythoneers Monthly Meeting: Wed, Mar 21, in Boulder, Colorad

2007-03-17 Thread frpythoneers
== Meeting: Wednesday, March 21, 2007 ==

 * Time: 6-8 PM

 * Location: bivio Software, Inc., 28th and Iris, Boulder, CO. Above
Hair Elite in  Suite S. There is abundant parking.

This Wednesday (March 21) we have a great lineup of PyCon 2007 talks
from local presenters:

 * Matt Boersma will present Write Less Code with XRC for wxPython:
an easier way to do GUI layout using wxWidget's XML-based resource
system.

 * Sean Reifschneider will present Python and vim: Two great tastes
that go great together. The vim editor includes extensive abilities
for customization and scripting. In addition to its own simple macro
language, vim also supports calling Python code. This Python code has
access back into vim for manipulating the edit buffer as well as
running normal vim commands. Examples demonstrated in this talk will
include automatically detecting indentation style (tabs/N spaces),
automatic update of DNS serial numbers when editing DNS zone files,
mail alias tab-expansion, and a time tracking application using a
domain specific vim as the user interface.

Other items to talk about:

 * BoulderSprint. The next sprint will be April 28 on the IPython1
Beta. This would be an excellent opportunity to learn about
decorators, Twisted, and other advanced Python concepts while helping
getting this amazing shell to beta status.

 * Google Summer of Code. The Python Software Foundation's application
to join GSoC was just approved. It's not too late to be a mentor. But
the student application deadline is March 24!

We will have food  drink available as usual. Hope to see you there!

More info: http://wiki.python.org/moin/FrontRangePythoneers

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

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


First version of qooxdoo json-rpc module has been released

2007-03-17 Thread Ferenczi Viktor
First release of JSON-RPC module for qooxdoo has been released.

qxjsonrpc is a new JSON-RPC backend for the qooxdoo JavaScript UI framework
( http://www.qooxdoo.org ). This module can be used to build server side
backends in python with very little effort.

Features:

- HTTP transport (GET and POST, including ScriptTransport)

- Build-in qooxdoo test server implementation for RPC_* tests

- Very fast JSON serialization through python-cjson-1.0.3x

Download and more information:
http://cx.hu/qxjsonrpc/

Simply running the module provides a qooxdoo test backend at: 127.0.0.1:8000

Example:

import qxjsonrpc

class MyService(object):
def getPi(self, *args):
print 'Called: getPi%r'%(args,)
return 3.14159265365

server=qxjsonrpc.HTTPServer()
server.setService('myservice', MyService())
server.serve_forever()

NOTE: qxjsonrpc uses an enhanced version of the very fast
python-cjson 1.0.3  JSON library called python-cjson-1.0.3x.
You must install python-cjson-1.0.3x before using qxjsonrpc.
You can download it from:  http://cx.hu/python-cjson

NOTE: I haven't tested this backend with real qooxdoo components,
so it may not work properly in such situations. Please drop me a mail
about your success or failure. Thanx.

You can send bug reports to: [EMAIL PROTECTED]
(This is only a temporary solution for bug reporting, of course.)

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

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


Enhanced python-cjson 1.0.3 version: 1.0.3x

2007-03-17 Thread Ferenczi Viktor
Enhanced version of python-cjson 1.0.3 has been released.

It's numbered 1.0.3x, where x stands for eXtension.

The main improvement is the ability to extend the JSON encoder and decoder 
with extensions functions to serialize/unserialize objects not in the 
original JSON specification. This is achieved without sacrificing the speed 
and stability of the original implementation. Please send bug reports to 
[EMAIL PROTECTED] and do not contact the original author (Dan Pascu) about this 
version.

Download and more information:
http://cx.hu/python-cjson/

Example to encode/decode python date and datetime objects as JavaScript Date 
objects:
import re
import cjson
import datetime

# Encoding Date objects:
def dateEncoder(d):
assert isinstance(d, datetime.date)
return 'new Date(Date.UTC(%d,%d,%d))'%(d.year, d.month, d.day)

json=cjson.encode([1,datetime.date(2007,1,2),2], extension=dateEncoder)
assert json=='[1, new Date(Date.UTC(2007,1,2)), 2]'

# Decoding Date objects:
re_date=re.compile('^new\sDate\(Date\.UTC\(.*?\)\)')
def dateDecoder(json,idx):
json=json[idx:]
m=re_date.match(json)
if not m: raise 'cannot parse JSON string as Date object: %s'%json[idx:]
args=cjson.decode('[%s]'%json[18:m.end()-2])
dt=datetime.date(*args)
return (dt,m.end()) # must return (object, character_count) tuple

data=cjson.decode('[1, new Date(Date.UTC(2007,1,2)), 2]', 
extension=dateDecoder)
assert data==[1,datetime.date(2007,1,2),2] 

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

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


[ANN] GCC 4.1.2 installer for Python distutils compilation

2007-03-17 Thread Giovanni Bajo
Hello,

This page:
   http://www.develer.com/oss/GccWinBinaries

contains a friendly Windows installer for GCC 4.1.2 (MinGW binary version), 
with full support for integrating it with Python installations so that it is 
used by distutils to compile Python extensions.


Direct download link:
   http://www.develer.com/~rasky/gcc-4.1.2-mingw-setup.exe


Who needs this package?

  * People who wants to use FLOSS tools to develop Python extensions.
  * People who wants to use the recent GCC 4.1.2 to develop Python extensions, 
given that it easily outperforms the 4-years-old Visual Studio .NET 2003.


What's special about this?

  * mingw.org still has GCC 3.4.2, so go figure. Also, you need to compose 
other packages together. This is a single installer with everything inside.
  * By default, MinGW GCC links with MSVCRT.DLL, and not MSVCR71.DLL (used by 
Python 2.4 and 2.5). Fixing this is pretty complicate, and there's much 
confusion (Google turns up red herrings). This package handles everything for 
you, and it just works.

-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Generating HTML containing XML in an INPUT tag

2007-03-17 Thread bendorge
Hi there,

Using Python, I'm auto-generating an HTML file that contains:
input type=hidden value=XXX /, where XXX is XML data (encoded
somehow).

Articles regarding unicode are making my head spin! Is there a way to
encode XML file contents to a hexadecimal string that could be decoded
on a PHP server?

I have an XML file that is generated based on user entries (GUI from
PythonCard).

After the XML file is created, I want the user to see an HTML preview,
and then click an Upload button on the page. Hidden in the page is the
tag I showed above.

I decided not to generate input type=file / because from a
usability standpoint, I want the user to create this file and upload
it to my PHP server in as few steps as possible. Also, I tried setting
the value to the XML file path...my browser security settings don't
like it and I'm sure other browsers won't like it either.

Any ideas?

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


Re: Mastering Python

2007-03-17 Thread John Nagle
Alex Martelli wrote:
 Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 
 
need to catch up quickly and master Python programming.How do you

Mastery and quickly are opposing terms G Took me 15 years on a job
using FORTRAN 77 and I still wouldn't have called myself a master. (I'm
more of a JoAT)
 
 
 My favorite Stars! PRT, mind you -- but when some language interests
 me enough, I do tend to master it... guess it's correlated with what
 Brooks saw as the ideal language lawyer in his surgical team
 approach, an intrinsic fascination with bunches of interconnected rules.

Python just isn't that complicated.  The syntax is straightforward,
and the semantics are similar to most other dynamic object-oriented languages.
If you know Perl or Smalltalk or LISP or JavaScript, Python does about
what you'd expect.

Execution model: dynamic stack-type interpreter.
Memory model: reference counting with backup garbage collector.
Syntax: roughly C-like, with indentation for structure.
Typing model: dynamic only
Object model: class definitions with multiple inheritance.
Object structure: dictionary hash.
Exception model: explicit throw/try/catch
Theading model: multiprogramming in interpreter.
Safe memory model: Yes.
Closures: Yes.
Design by contract: No.

That's Python.

Biggest headache is finding out what doesn't work in the libraries.

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


Re: Mastering Python

2007-03-17 Thread Paul Rubin
John Nagle [EMAIL PROTECTED] writes:
   Execution model: dynamic stack-type interpreter.

Erm, the iterator protocol makes the above a little more complicated.

 Biggest headache is finding out what doesn't work in the libraries.

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


Re: Weekly Python Patch/Bug Summary

2007-03-17 Thread Dick Moores


May I ask a dumb question here? It isn't clear to me what to do with
these patches. For most of them there is something like, Committed
as r54386 and r54387. I'm familiar with updating the editor Ulipad
to the latest revision, using software such as TortoiseSVN and RapidSVN.
Is that what is meant? And if so, what's the URL of the trunk?
Thanks,
Dick Moores




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

Re: Weekly Python Patch/Bug Summary

2007-03-17 Thread Terry Reedy

Dick Moores [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| May I ask a dumb question here? It isn't clear to me what to do with 
these patches. For most of them there is something like, Committed as 
r54386 and r54387. I'm familiar with updating the editor Ulipad to the 
latest revision, using software such as TortoiseSVN and RapidSVN. Is that 
what is meant? And if so, what's the URL of the trunk?
-

Yes, those are svn revision numbers.  Start at svn.python.org.

Most people ignore the patches.  Some look at them to know what to expect 
in the next releases.  A few download to a local svn repository either to 
work on the code or build a bleeding edge python to test with their code. 
Good luck.

tjr



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


Re: distributing python software in jar like fashion

2007-03-17 Thread Gary Duzan
In article [EMAIL PROTECTED],
John Nagle  [EMAIL PROTECTED] wrote:
 Were Python eggs a flop, or what?

 We need to have one packager that everyone agrees on.
Otherwise, installs become a mess, and then you have to have
installers that handle multiple packagers.

   I think the point about Squisher is that you don't have to
install it. You can either import it or run it directly. I'm mostly
interested in it as a way to package a script with a few Python
and C modules, dump it in the field, and run python myscript.pyc
to execute it, with no need for anything but the base Python to be
installed on the remote site, and just one file to copy.

Gary Duzan
Motorola CHS


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


Re: Odd error

2007-03-17 Thread John Machin
On Mar 17, 4:34 pm, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I'm trying to use a script that I originally wrote on a Mac Classic
 machine and have moved to a Windows XP machine.

 I can open the script and edit the thing, but when I try to run it in
 I get:
 Exception in Tkinter callback
 Traceback (most recent call last):
   File C:\Python25\lib\lib-tk\Tkinter.py, line 1403, in __call__
 return self.func(*args)
   File C:\Python25\lib\idlelib\MultiCall.py, line 151, in handler
 r = l[i](event)
   File C:\Python25\lib\idlelib\ScriptBinding.py, line 151, in
 run_module_event
 dirname = os.path.dirname(filename)
   File C:\Python25\lib\ntpath.py, line 207, in dirname
 return split(p)[0]
   File C:\Python25\lib\ntpath.py, line 172, in split
 while head2 and head2[-1] in '/\\':
 TypeError: 'int' object is not iterable

 I've converted the text to windows format, and the other scripts that
 I transferred at the same time work.

 What's going on here?

The following demonstrate the correct behaviour of ntpath.split():

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type help, copyright, credits or license for more information.
 import ntpath
 ntpath.split('foo')
('foo', '')
 ntpath.split('foobar')
('foobar', '')
 ntpath.split('foobar')
('foo', 'bar')
 ntpath.split('foo\\bar')
('foo', 'bar')
 ntpath.split('bar')
('', 'bar')

I can't see how this error could arise from the line:
while head2 and head2[-1] in '/\\':
The only possible iterable is the constant '/\\' ...

You may have a corrupt Python 2.5 installation; try the above tests;
if one fails, delete any ntpath.pyc and/or ntpath.pyo and try again.

I'm suspicious of the 'lib' directory name; standard Python
installations on Windows call the directory 'Lib' AFAIK; how did you
install Python?

HTH,
John

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


Re:

2007-03-17 Thread Shane Geiger

Milton,

This isn't terribly elegant, but it gets the job done:

dirs = ['C:\Images', 'C:\Images\2006', 'C:\Images\2007', 'C:\Music', 
'C:\Files', 'C:\Software', 'C:\Software\Python', 'C:\Software\iTunes'] 

exclude_list = 
['Software','Images'] 



def foo(d):
   retval = d
   for item in exclude_list:
   if item in d:
   retval = False
   return retval

dirs = map(foo, dirs)
dirs = filter(bool, dirs)  # removes the Falses
print dirs


Milton Segura wrote:

Hello, I'm trying to exclude files from a list using the following code:
 
for item in dirs:

if item.find('Software')  -1:
dirs.remove(item)
elif item.find('Images')  -1:
dirs.remove(item)
 
let's supose dirs = ['C:\Images', 'C:\Images\2006', 'C:\Images\2007', 
'C:\Music', 'C:\Files', 'C:\Software', 'C:\Software\Python', 
'C:\Software\iTunes']
 
For some reason.. it just won't exclude them.

I'd like to know why and how to fix it.
Thanks in advance.
Milton


Explore the seven wonders of the world Learn more! 
http://search.msn.com/results.aspx?q=7+wonders+worldmkt=en-USform=QBRE


--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

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

Re: (unknown)

2007-03-17 Thread Gabriel Genellina
En Sat, 17 Mar 2007 03:54:22 -0300, Milton Segura [EMAIL PROTECTED]  
escribió:

 Hello, I'm trying to exclude files from a list using the following code:
 for item in dirs:if item.find('Software')  -1: 
 dirs.remove(item)elif item.find('Images')  -1: 
 dirs.remove(item)
 For some reason.. it just won't exclude them.
 I'd like to know why and how to fix it.

Don't iterate over the list and alter it at the same time; the iterator  
gets confused.
Iterate over a copy:

for item in dirs[:]:
if item.find(...)

or backwards:

for item in reversed(dirs):
if item.find(...)

-- 
Gabriel Genellina

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


Re: TypeError: 'module' object is not callable

2007-03-17 Thread Gabriel Genellina
En Fri, 16 Mar 2007 14:42:49 -0300, [EMAIL PROTECTED] escribió:

 and i tried to call profile('t.printworld()')

 but i received the following error:
 Traceback (most recent call last):
   File stdin, line 1, in ?
 TypeError: 'module' object is not callable

It's always better to post the *whole* code.
I assume you wrote:
import profile
profile('...')
But profile is the module name; you want to call the `run` function inside  
the profile module instead:

import profile
profile.run('t.printworld()')

Look at the docs for the profile module at  
http://docs.python.org/lib/lib.html or typing help(profile) at the  
interpreter prompt.

-- 
Gabriel Genellina

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


Re: import error

2007-03-17 Thread Gabriel Genellina
En Fri, 16 Mar 2007 23:49:43 -0300, Nick Burns [EMAIL PROTECTED]  
escribió:

 Quick question. I am running python on windows xp. i want to import my  
 own
 module mymod. However, when I try to import it i get the error message  
 ImportError:
 no module named mymod.

 mymod is located in a directory that is part of the computer's path  
 env
 variable. Imports fine if 'mymod' is in the current working directory,  
 but not
 otherwise. i had thought that by saving 'mymod'within my normal path  
 that it
 would import successfully, but this is not the case.

Python does not use the system PATH environment variable. Doing this:

import sys
print sys.path

you will see the list of directories that Python would try. Try saving  
your module inside site-packages.

-- 
Gabriel Genellina

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


Re: Finding the insertion point in a list

2007-03-17 Thread Martin Blume
7stud schrieb 
 How about:
 
 ---
 x = [0, 100, 200, 1000]
 y = -1
 inserted = False
 
 for i in range(len(x)):
 if(y = x[i]):
 x.insert(i, y)
 inserted = True
 break
 if(not inserted): x.append(y)
 
 print x
 


You can get rid of the sentinel inserted using the 
else clause of the for loop:

for i in range(len(x)):
if (y = x[i]):
x.insert(i, y)
break
else: x.append(y)

Python is cool :-)

IMHO. HTH.
Martin


 

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


Re: lock problem

2007-03-17 Thread Gabriel Genellina
En Fri, 16 Mar 2007 04:40:27 -0300, Ritesh Raj Sarraf [EMAIL PROTECTED]  
escribió:

 Leo Kislov wrote:

 You're changing environmental variable __kabc_ldap that is shared
 between your threads. Environment is not designed for that kind of
 usage, it was designed for settings. Either use an option to set
 output file or just redirect stdout. If the interface of ldapsearch is
 so lame that it requires environmental variable use env to set the
 variable: env __kabc_ldap=/tmp/wrjhdsf ldapsearch ...

 The environment variable is set with temp_file_name which gets the name  
 from
 tempfile.mkstemp(), which is run in every thread. So I don't think the
 environment variable is going to be the same.

But the environment is global for all threads.
I don't know how ldapsearch works, but can't you pass it an additional  
argument, instead of setting an environment variable? From the long  
commandline you're building, I bet it has a suitable option.
Or, instead of os.system, use subprocess.Popen, wich lets you specify the  
new environment of the child process.

-- 
Gabriel Genellina

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


Re: File extension

2007-03-17 Thread Gabriel Genellina
En Fri, 16 Mar 2007 19:59:09 -0300, Anil Kumar [EMAIL PROTECTED]  
escribió:

 But when I try a python script with extension .sh in windows, the file is
 not getting recognized by the Python interpreter. Is this supported? Or  
 is
 there any way we can achieve the same?

C:\TEMPtype test.sh
print Hello!

C:\TEMPpython test.sh
Hello!

For a *script* that you run explicitely, Python doesn't care of the  
extension. But a *module* (used with the import statement) must be a  
.py/.pyc/.pyo
Also, if you run the script with: python scriptname.sh, it's ok; but if  
you run it just using: scriptname.sh, won't work; Windows uses the file  
extension to determine the program to run, instead of the !# line.

 The reason I am trying to change the extension is, it reduces lot of  
 porting
 changes. No need to go to each of our file which were referencing .sh  
 file
 before and change it to .py.

I assume you're not using Cygwin - you can create a stub version of each  
script, so that foo.sh contains: python foo.py, and associate .sh  
extension with cmd.exe

-- 
Gabriel Genellina

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


Re: Weekly Python Patch/Bug Summary

2007-03-17 Thread Dick Moores
At 01:32 AM 3/17/2007, Terry Reedy wrote:

Dick Moores [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
| May I ask a dumb question here? It isn't clear to me what to do with
these patches. For most of them there is something like, Committed as
r54386 and r54387. I'm familiar with updating the editor Ulipad to the
latest revision, using software such as TortoiseSVN and RapidSVN. Is that
what is meant? And if so, what's the URL of the trunk?
-

Yes, those are svn revision numbers.  Start at svn.python.org.

I thought I'd give 
http://svn.python.org/projects/python/branches/release25-maint/ 
(the latest release (plus bug fixes) of Python) a try. I first backed 
up my Python25 folder (I'm using Win XP). Then with Python 25 open I 
opened the Explorer context menu for the folder and then the 
TortoiseSVN sub-menu. There doesn't seem to have a menu item that 
will enable me to update. I tried Export... and entered 
http://svn.python.org/projects/python/branches/release25-maint/ as 
URL of repository, but that choice seems to expect the Python25 
folder to be empty. Can you tell me what to do to just update?

Dick 

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


ECCOMAS VipIMAGE 2007 - Abstracts Submission Period Extended in TWO WEEKS

2007-03-17 Thread [EMAIL PROTECTED]
International ECCOMAS Thematic Conference VipIMAGE 2007 - I ECCOMAS
THEMATIC
CONFERENCE ON COMPUTATIONAL VISION AND MEDICAL IMAGE PROCESSING
17-19th
October 2007, FEUP, Porto, Portugal
http://www.fe.up.pt/VIPIMAGE


We would appreciate if you could distribute this information by your
colleagues and co-workers.

Dear Colleague,

The Organizing Committee of VipMAGE has decided to extend the
submission
period in two weeks (March 31, 2007).

More details regarding VipIMAGE can be found in the conference
website:
http://www.fe.up.pt/VIPIMAGE

We are looking forward to see you in Porto next October.


Important dates

Submission of extended abstracts: March 31, 2007; Authors
Notification:
April 15, 2007; Lectures and Final Papers: May 15, 2007; Early
registration
fee: May 31, 2007.


Invited Lectures

- Automatic Generation of Computer Models from Multi-modal Bio-
medical
Imaging - Chandrajit Bajaj, USA
- Computational Bioimaging and Visualization - Chris Johnson, USA
- From Geometrical Models to Physiological Models of the Human Body -
Hervé
Delingette, France
- Latest advances in Cardiovascular Informatics - Ioannis A.
Kakadiaris, USA
- Robust Algorithms for Deformable Contours - Jorge S. Marques,
Portugal
- Image Sequence Evaluation - Juan J. Villanueva, Spain
- Fast Surface Segmentation and remeshing by finding geodesics -
Laurent
Cohen, France
- Processing of Simultaneous acquisition of EEG and fMRI - Mario
Forjaz
Secca, Portugal
- Automatic Construction of Statistical Shape Models using Non-Rigid
Registration - Tim Cootes, UK
- Theory of Digital Manifolds and its Applications to Medical Imaging
-
Valentin Brimkov, USA  Reinhard Klette, NZ


Kind regards,

João Manuel R. S. Tavares
Renato Natal Jorge
(conference co-chairs)

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


Re: urlopen not thread safe

2007-03-17 Thread Gabriel Genellina
En Thu, 15 Mar 2007 21:12:46 -0300, John Nagle [EMAIL PROTECTED]  
escribió:

 I was looking at the code for urllib, and there's
 some undocumented FTP cacheing code in there that's not thread safe.
 The documentation for urllib

 Is there any good reason to keep that code in urllib?
 Unless something critical uses that undocumented feature,
 that code probably ought to come out.  Comments?

Maybe the default should be None, like tempcache; anyone interested could  
assign to the ftpcache instance attribute.

-- 
Gabriel Genellina

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


Re: Finding the insertion point in a list

2007-03-17 Thread John Machin
On Mar 17, 5:42 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
 Steven D'Aprano [EMAIL PROTECTED] writes:
  or even

  len(filter(lambda t, y=y: yt, x))

 How about

min(i for i,t in enumerate(x) if t = y)

 or

max(i for i,t in enumerate(x) if t = y)

 Those are actually pretty direct.

I'd hate to see indirect. Worse, the min-using gizmoid crashes when
y  x[-1] -- all your ifs are belong to False.


 x
[0, 100, 200, 1000]
 tests = [0, 1, 100, 150, 1000, 2000]
 [(y, max(i for i,t in enumerate(x) if t = y)) for y in tests]
[(0, 0), (1, 0), (100, 1), (150, 1), (1000, 3), (2000, 3)]

Looks OK, iff one is happy with the OP's strange usage of insert
point.
 xc = x[:]
 xc.insert(1, 150)
 xc
[0, 150, 100, 200, 1000]

Whoops.

Try this for size:

 [(y, sum(t = y for t in x)) for y in tests]
[(0, 1), (1, 1), (100, 2), (150, 2), (1000, 4), (2000, 4)]

Cheers,
John



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


Re: Returning other instance from __init__ - I need help

2007-03-17 Thread Gabriel Genellina
En Fri, 16 Mar 2007 22:05:05 -0300, Paulo da Silva  
[EMAIL PROTECTED] escribió:

 When debugging, I found this is wrong!!!
 Would someone please clarify what do I have to return from
 __new__?

Try this. I used a classmethod for load, it may be easier to subclass.

class C(object):

 def __new__(cls, filename=None, foo=None, bar=None):
 if filename is not None:
 return cls.load(filename)
 inst = super(C, cls).__new__(cls)
 inst.foo = foo
 inst.bar = bar
 return inst

 @classmethod
 def load(cls, filename):
 inst = super(C, cls).__new__(cls)
 inst.foo = some foo loaded from +filename
 inst.bar = some bar loaded from +filename
 return inst

class D(C):
 @classmethod
 def load(cls, filename):
 inst = super(D, cls).__new__(cls)
 inst.foo = D foo loaded from +filename
 inst.bar = D bar loaded from +filename
 return inst


c1 = C(foo=1, bar=2)
print c1=, c1
print c1.foo=, c1.foo
print c1.bar=, c1.bar
c2 = C(filename=xxx.txt)
print c2=, c2
print c2.foo=, c2.foo
print c2.bar=, c2.bar

d1 = D(foo=10, bar=20)
print d1=, d1
print d1.foo=, d1.foo
print d1.bar=, d1.bar
d2 = D(filename=yyy.txt)
print d2=, d2
print d2.foo=, d2.foo
print d2.bar=, d2.bar


-- 
Gabriel Genellina

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


Re: File extension

2007-03-17 Thread Steve Holden
Anil Kumar wrote:
 Hi,
  
 Can Python Script can have different extensions like .sh etc Or Is 
 .py is mandatory to be present as the extension for the Python Script.
  
The interpreter itself doesn't really care. The issues you are hotting 
are due to operating system. and command shell differences.

 We have an application where the script was initially written in shell 
 script with extension .sh. Now we are migrating this script to be run in 
 both Unix and Windows, so using Python for migration.
  
Good for you!

 I have created a new Python Script porting all the changes in shell 
 script and it is working fine in Unix/Linux operating system. Later I 
 changed the extension of the file from .py to .sh, even then it worked.
  
The Unix command interpretation mechanism uses PATH as a list of 
directories to search for the named command file (the first word of the 
expanded command line). It then looks for the magic string #! at the 
start of the executable file and, if it finds that string, it passes the 
file to the interpreter named in the rest of the line for execution as a 
program.

Your Python files probably begin with something like

#!/usr/bin/python

or

#!/usr/bin/env python

 But when I try a python script with extension .sh in windows, the file 
 is not getting recognized by the Python interpreter. Is this supported? 
 Or is there any way we can achieve the same?
  
In Windows, alas, the mechanism is less versatile. The command 
interpreter uses an environment variable called PATHEXT to decide which 
extensions to check when it sees a command that it can't find directly. 
For example, my PATHEXT variable is currently

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

(you'll observe I have given up on the PATHEXT mechanism - it's too much 
of a pain in the butt for me, so I just code explicit calls to the 
python interpreter).

It looks on the PATH for a file with the given name and each extension, 
and when it finds one it then runs the interpreter registered for that 
type of file.

 The reason I am trying to change the extension is, it reduces lot of 
 porting changes. No need to go to each of our file which were 
 referencing .sh file before and change it to .py.
  
 Any Help would be greatly Appreciated.
  
You could cheat ... if you register the .SH extension as to be handled 
by the python interpreter and then add .SH to PATHEXT this should work 
under Windows.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the insertion point in a list

2007-03-17 Thread Steve Holden
Paul Rubin wrote:
 Steven D'Aprano [EMAIL PROTECTED] writes:
 or even

 len(filter(lambda t, y=y: yt, x))
 
 
 How about 
 
min(i for i,t in enumerate(x) if t = y)
 
 or
 
max(i for i,t in enumerate(x) if t = y)
 
 Those are actually pretty direct.

How about a solution (like the bisect one suggested almost as soon as 
this thread started) that doesn't iterate over the whole list.

Having said which, for the promoted use cases I agree that the append() 
and sort() paradigm wins hands down until it starts to make a real and 
observable difference to the run time.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings   http://holdenweb.blogspot.com

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


Re: import error

2007-03-17 Thread Steve Holden
Gabriel Genellina wrote:
 En Fri, 16 Mar 2007 23:49:43 -0300, Nick Burns [EMAIL PROTECTED]  
 escribió:
 
 Quick question. I am running python on windows xp. i want to import my  
 own
 module mymod. However, when I try to import it i get the error message  
 ImportError:
 no module named mymod.

 mymod is located in a directory that is part of the computer's path  
 env
 variable. Imports fine if 'mymod' is in the current working directory,  
 but not
 otherwise. i had thought that by saving 'mymod'within my normal path  
 that it
 would import successfully, but this is not the case.
 
 Python does not use the system PATH environment variable. Doing this:
 
 import sys
 print sys.path
 
 you will see the list of directories that Python would try. Try saving  
 your module inside site-packages.
 

Or investigate appropriate settings of the PYTHONPATH environment 
variable, whose elements will be added to sys.path at interpreter 
startup. The path environment variable is for locating executables, 
not Python libraries.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings   http://holdenweb.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


cannot start IDLE in WinXP

2007-03-17 Thread imx
Hi,

Enviroment: WinXP sp2, python 2.5
problem: click IDLE using shorcut menu or run phthonw.exe directly,
nothing happen! But running python.exe from the command line is fine.

I searched this issue on the net and this forum and tried some
suggestions but with no luck.

Any ideas?

Thanks in advance,
Xiong

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

[Announce] Scribes 0.3.1 Released

2007-03-17 Thread mystilleef
Scribes is python editor for *nix and GNOME that balances simplicity
with power. This release features extensibility via Python plugins,
auto-completion enhances, snippets improvement, automatic replacement
and correction, a new minimalist interface, performance optimizations
and more...

release note: http://scribes.sourceforge.net/release-note-0-3-1.html

Flash Demo: http://scribes.sf.net/demo.htm

GIF Demo: http://www.minds.may.ie/~dez/images/blog/scribes.html

download: http://scribes.sf.net/download.html

templates: http://scribes.sf.net/templates.tar.bz2

website: http://scribes.sf.net/

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


Re: Finding the insertion point in a list

2007-03-17 Thread John Machin
On Mar 17, 9:46 pm, Steve Holden [EMAIL PROTECTED] wrote:
 Paul Rubin wrote:
  Steven D'Aprano [EMAIL PROTECTED] writes:
  or even

  len(filter(lambda t, y=y: yt, x))

  How about

 min(i for i,t in enumerate(x) if t = y)

  or

 max(i for i,t in enumerate(x) if t = y)

  Those are actually pretty direct.

 How about a solution (like the bisect one suggested almost as soon as
 this thread started) that doesn't iterate over the whole list.

 Having said which, for the promoted use cases I agree that the append()
 and sort() paradigm wins hands down until it starts to make a real and
 observable difference to the run time.


Unfortunately for sort/append, the OP wants to find the insertion
point -- he hasn't mentioned actually doing the insertion.


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


Re: lock problem

2007-03-17 Thread Ritesh Raj Sarraf
Leo Kislov wrote:

 But you miss the fact that there is only one environment per process.
 

Oh!! I think I get your point.

There'd be only one __kabc_ldap environment variable to which all the threads
would be overwriting.

Hmmm!! Yes, you're correct. Thanks for pointing it out.

Ritesh
-- 
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism, stealing from many is research.
The great are those who achieve the impossible, the petty are those who
cannot - rrs

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


Re: lock problem

2007-03-17 Thread Ritesh Raj Sarraf
Leo Kislov wrote:

 But you miss the fact that there is only one environment per process.

Maybe there's a confusion.
The environment variable that I'm setting has noting to do with ldapsearch. I
use the environment variable as a filename to which ldapsearch can redirect its
output. And that I do is because the output can be huge and useless.
Then I do some pattern matching on that file and filter my data and then delete
it.

If you think I still am missing something important, request you to describe it.

Thanks,
Ritesh
-- 
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism, stealing from many is research.
The great are those who achieve the impossible, the petty are those who
cannot - rrs

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


Re: Writing python module in C: wchar_t or Py_UNICODE?

2007-03-17 Thread Yury

Carsten Haese wrote:

 You should familiarize yourself with the Python/C API documentation. It
 contains the answers to all the above questions.

 http://docs.python.org/api/arg-parsing.html says this about the u
 format character: a pointer to the existing Unicode data is stored into
 the Py_UNICODE pointer variable whose address you pass.

 http://docs.python.org/api/unicodeObjects.html says this about
 Py_UNICODE: On platforms where wchar_t is available and compatible with
 the chosen Python Unicode build variant, Py_UNICODE is a typedef alias
 for wchar_t to enhance native platform compatibility.

 The first quote says that, to be strictly correct, login should be a
 Py_UNICODE*, but the second quote says that under the right
 circumstances, Py_UNICODE is the same as wchar_t. It's up to you to
 determine if your platform provides the right circumstances for this to
 be the case.

 Hope this helps,

 Carsten.

Thanks for reply,
sorry for asking questions while not checked the manual.
Also sorry for my wierd english :)

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


Re: SQLite3, data not found

2007-03-17 Thread jim-on-linux
On Friday 16 March 2007 18:23, Jerry Hill wrote:
 On 3/16/07, jim-on-linux [EMAIL PROTECTED] 
wrote:
  Below, the first select produces results but,
  after closing then re-opening the database
  the select produces an empty list.  Anyone
  know the reason ??

 When you first open a connection, you
 implicitly begin a transaction. You need to
 call con.commit() before you close the
 connection, or your transaction will be rolled
 back when you close() it.  If don't want to
 bother with transaction handling, you can turn
 it off when you open the connection, like this:
 con = sqlite3.connect('myData',
 isolation_level=None)

 See the Python Database API 2.0 PEP for more
 details about the behavior required of DB-API
 2.0 compliant interfaces:
 http://www.python.org/dev/peps/pep-0249/

 --
 Jerry

Thanks, this saves a lot of con.commit action.
And the website is valuable.

jim-on-linux 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mastering Python

2007-03-17 Thread Alex Martelli
John Nagle [EMAIL PROTECTED] wrote:
   ...
 Mastery and quickly are opposing terms G Took me 15 years on a job
 using FORTRAN 77 and I still wouldn't have called myself a master. (I'm
   ...
 Python just isn't that complicated.  The syntax is straightforward,

Neither is/was Fortran 77, net perhaps of a few syntax quirks that were
easily avoided; yet few practitioners took the trouble (for example) of
learning what manners of data aliasing (e.g. between routine parameters
and/or data in COMMON blocks) were legal and which were not -- such a
simple rule (if you write data through an alias and read or write the
same memory through a different alias, you're breaking the rules of the
language and the compiler's free to make dragons fly out of your nose),
yet I've lost count of the number of times I've seen it broken during my
Fortran days (broken by professional programmers who used Fortran to
make a living and yet didn't care enough to know better, mind you -- I'm
not talking about accidental mistakes, which of course can easily happen
for a rule that the compiler need not enforce, but total ignorance of
this simple rule).


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


tkinter grid vs pack

2007-03-17 Thread Gigs_
For what is grid better than pack, and otherwise?

thanks in advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a better solution for GUI in python

2007-03-17 Thread Rainer Grimm
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?
 
Hallo.

Hava a look at http://www.awaretek.com/toolkits.html .

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


Private data

2007-03-17 Thread Dustan
http://dustangroups.googlepages.com/privateattributesinpython

This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes and
static function variables (I'm not 100% sure if that's the correct
terminology, but you get what I mean). I haven't tried to create
private instance attributes, mainly because it would just be too
difficult, and it would be awful syntax. I'm not considering actually
using this, but I do have a couple questions about it.

1. Has anyone else ever come up with something like this? I can't
imagine I'm the only person who's ever thought of this.
2. Is it possible to hack into something like this? ie, would it be
possible to see and change these variables from client code (assuming
the data manager has been properly removed from sight, as shown on the
last line of class block TestPrivateClassAttributes)?

To avoid utter confusion, you may want to look at
TestPrivateClassAttributes before looking at the actual implementation
of PrivateDataEngine. If you're still confused, feel free to ask
what's going on here (and I'm open to suggestions on how to make it
clearer).

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


Re: Finding the insertion point in a list

2007-03-17 Thread 7stud
On Mar 17, 4:12 am, Martin Blume [EMAIL PROTECTED] wrote:
 7stud schrieb



  How about:

  ---
  x = [0, 100, 200, 1000]
  y = -1
  inserted = False

  for i in range(len(x)):
  if(y = x[i]):
  x.insert(i, y)
  inserted = True
  break
  if(not inserted): x.append(y)

  print x
  

 You can get rid of the sentinel inserted using the
 else clause of the for loop:

 for i in range(len(x)):
 if (y = x[i]):
 x.insert(i, y)
 break
 else: x.append(y)

 Python is cool :-)

 IMHO. HTH.
 Martin

for-else?  Neat.

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


Re: Python shell on mac os x

2007-03-17 Thread Kevin Walzer
7stud wrote:
 On Mar 16, 2:53 am, [EMAIL PROTECTED] wrote:
 or go tohttp://pythonmac.org/packages/
  and you have python 2.5 or python 2.4.4 with readline support
 
 The download instructions seem to steer Mac users to version 2.4.4
 because it has more modules available. What is the consensus on that?
 

If you just want binary packages installed, it might make sense to use 
2.4.4, but building new packages with 2.5 is easy: either use 
easy_install or sudo python setup.py. I've had no trouble building the 
stuff I need with 2.5.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


read a web page using python

2007-03-17 Thread myTesterFrench
Hi All,

Kindly, could you someone tell me how to read a page(any web site)
using Python, what method to be used ?

Paris

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


Re: SQLite3, data not found

2007-03-17 Thread John Nagle
jim-on-linux wrote:
 On Friday 16 March 2007 18:23, Jerry Hill wrote:
 
On 3/16/07, jim-on-linux [EMAIL PROTECTED] 
 
 wrote:
 
Below, the first select produces results but,
after closing then re-opening the database
the select produces an empty list.  Anyone
know the reason ??

When you first open a connection, you
implicitly begin a transaction. You need to
call con.commit() before you close the
connection, or your transaction will be rolled
back when you close() it.  If don't want to
bother with transaction handling, you can turn
it off when you open the connection, like this:
con = sqlite3.connect('myData',
isolation_level=None)

See the Python Database API 2.0 PEP for more
details about the behavior required of DB-API
2.0 compliant interfaces:
http://www.python.org/dev/peps/pep-0249/

--
Jerry
 
 
 Thanks, this saves a lot of con.commit action.
 And the website is valuable.
 
 jim-on-linux 

Don't turn off atomic transactions, use them.
Otherwise, two copies of your program running at the
same time will probably not do what you want.
Just call commit at the end of each transaction.

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


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
i have no NumPy to test it...
without Psyco Anton's code is the winner: ~48sec vs ~58sec of my code
But with Psyco my runtime is ~28sec; Anton's - ~30sec (PC: 1.6 ghz,
512 mb)
Not so bad.. keeping in mind that 256000 billions quadruplets to
check :)


import psyco, time
psyco.full()
t = time.clock()

def main():
  q,w,e,r,sch,h = [],[],[],[],0,{}

  f = open(D:/m4000.txt,rt)
  for o in range(f.readline()):
row = map(int, f.readline().split())
q.append(row[0])
w.append(row[1])
e.append(row[2])
r.append(row[3])
  f.close()

  for x in q:
for y in w:
  if h.has_key(x+y):
h[x+y] += 1
  else:
h[x+y] = 1

  for x in e:
for y in r:
  if h.has_key(-(x+y)):
sch += h[-(x+y)]

  q,w,e,r,h = None,None,None,None,None
  print sch

main()
print time.clock() - t

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


Re: read a web page using python

2007-03-17 Thread Luuk

[EMAIL PROTECTED] schreef in bericht 
news:[EMAIL PROTECTED]
 Hi All,

 Kindly, could you someone tell me how to read a page(any web site)
 using Python, what method to be used ?

 Paris


http://www.amk.ca/python/howto/sockets/


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


Re: Phase change material ...

2007-03-17 Thread Brian Whatcott
On Sat, 10 Mar 2007 20:23:27 GMT, Dan Bloomquist
[EMAIL PROTECTED] wrote:

[EMAIL PROTECTED] wrote:

 On Mar 8, 5:57 pm, martinl [EMAIL PROTECTED] wrote:
 
Hi All,
I'm looking for a substance that does a phase change at between 60 and
100 C.

I settled for hurricane wax. (IGI-1260). But that, because I felt it 
would suit my application, domestic heating. I have 3 thousand pounds of 
the stuff.

http://lakeweb.com/boiler/tubes.jpg

Best, Dan.


I don't know how I could have overlooked this note for several days.
It sounds like a wonderfully adventurous design.
I have not been keeping up with the literature,  but phase change
media ought to be the way to go.
After all, if four tons of ice could hold a house down with a temp
differential of 20 degreesC or so, then  1.5 tons of wax might have a
good  chance of holding the temperature up with a temp differential
 of 80-20degC= 60 degrees.

Wonder what the latent heat is? Less than 340 kJ/kg I imagine.
How much did it cost?

Brian  Whatcott   Altus OK
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read a web page using python

2007-03-17 Thread Lawrence Oluyede
[EMAIL PROTECTED] wrote:
 Kindly, could you someone tell me how to read a page(any web site)
 using Python, what method to be used ?

import urllib2
res = urllib2.urlopen(url)
page = res.read()

See: http://www.voidspace.org.uk/python/articles/urllib2.shtml

-- 
Lawrence, oluyede.org - neropercaso.it
It is difficult to get a man to understand 
something when his salary depends on not
understanding it - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Odd error

2007-03-17 Thread [EMAIL PROTECTED]
I installed it using the regular download form python.org.  I went
back and did a lot of testing with the file, commenting out most of
it, seeing what would actually run, and it seems I had a normal
semantic error:

self.data(one).append(item)

and data is in fact a dictionary, not a callable object.  What gets me
is the massive red herring this error is.  I wasn't doing anything
with ntpath in the script.  The script selectively extracts
information from an XML file, that's all.

Thanks,

Josh

On Mar 17, 2:30 am, John Machin [EMAIL PROTECTED] wrote:

 The following demonstrate the correct behaviour of ntpath.split():

 Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
 (Intel)] on win32
 Type help, copyright, credits or license for more information. 
 import ntpath
  ntpath.split('foo')
 ('foo', '')
  ntpath.split('foobar')
 ('foobar', '')
  ntpath.split('foobar')
 ('foo', 'bar')
  ntpath.split('foo\\bar')
 ('foo', 'bar')
  ntpath.split('bar')

 ('', 'bar')

 I can't see how this error could arise from the line:
 while head2 and head2[-1] in '/\\':
 The only possible iterable is the constant '/\\' ...

 You may have a corrupt Python 2.5 installation; try the above tests;
 if one fails, delete any ntpath.pyc and/or ntpath.pyo and try again.

 I'm suspicious of the 'lib' directory name; standard Python
 installations on Windows call the directory 'Lib' AFAIK; how did you
 install Python?

 HTH,
 John


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


Re: Weekly Python Patch/Bug Summary

2007-03-17 Thread Terry Reedy

Dick Moores [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| I thought I'd give
| http://svn.python.org/projects/python/branches/release25-maint/
| (the latest release (plus bug fixes) of Python) a try. I first backed
| up my Python25 folder (I'm using Win XP). Then with Python 25 open I
| opened the Explorer context menu for the folder and then the
| TortoiseSVN sub-menu. There doesn't seem to have a menu item that
| will enable me to update. I tried Export... and entered
| http://svn.python.org/projects/python/branches/release25-maint/ as
| URL of repository, but that choice seems to expect the Python25
| folder to be empty. Can you tell me what to do to just update?

Just to make sure you know, the svn repository is source code that you will 
have to compile.  If TortoiseSVN only copies repositories and reads and 
does not update, then you need svn itself.  But I know almost nothing about 
it except the name.  In any case, to update a local code repository, you 
would need one to begin with by downloading the whole think initially.

tjr



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


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread bearophileHUGS
n00m:
 i have no NumPy to test it...
 without Psyco Anton's code is the winner: ~48sec vs ~58sec of my code
 But with Psyco my runtime is ~28sec; Anton's - ~30sec (PC: 1.6 ghz,
 512 mb)
 Not so bad.. keeping in mind that 256000 billions quadruplets to
 check :)

I have oiled it a bit, you can try the speed of this too (for dicts in
is always faster than has_key).

from collections import defaultdict
import time, psyco

def main():
sch = 0
q,w,e,r = [],[],[],[]
h = defaultdict(int)

datafile = file(m1000.txt)
datafile.next()
xrows = (map(int, line.split()) for line in datafile)
q, w, e, r = zip(*xrows)

for x in q:
for y in w:
h[x+y] += 1

for x in e:
for y in r:
if -x-y in h:
sch += h[-x-y]

print sch

t = time.clock()
psyco.full()
main()
print round(time.clock() - t, 2), secs

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


Re: Odd error

2007-03-17 Thread Terry Reedy

[EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
|I installed it using the regular download form python.org.  I went
| back and did a lot of testing with the file, commenting out most of
| it, seeing what would actually run, and it seems I had a normal
| semantic error:
|
| self.data(one).append(item)
|
| and data is in fact a dictionary, not a callable object.  What gets me
| is the massive red herring this error is.  I wasn't doing anything
| with ntpath in the script.  The script selectively extracts
| information from an XML file, that's all.

When you run a script from IDLE, it saves it to disk, and in the process of 
saving, IDLE looks at the path.  I don't think your script ever ran.  At 
least that is what I gathered from the traceback.  I agree with JM: the 
traceback and error message do not match, so this is indeed an 'odd' error.

Terry Jan Reedy



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


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 for x in e:
 for y in r:
 if -x-y in h:
 sch += h[-x-y]

I wonder whether

g = h.get
for x in e:
for y in r:
if -x-y in h:
sch += g(-x-y, 0)

might be a little bit faster.  Also, -x-y could be saved in a variable.

It's unfortunate that array.array objects don't support the .sort()
operation.  It would be interesting to compare the sorting-based scheme
with the hashing-based one under psyco.  O(n**2*log(n)) local memory 
references might be faster than O(n**2) hash operations and random
lookups that almost always miss the cache.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread mark . dufour

Paul Rubin wrote:
 n00m [EMAIL PROTECTED] writes:
  Two first outputs is of above (your) code; next two - of my code:

 Yeah, I see now that we both used the same algorithm.  At first glance
 I thought you had done something much slower.  The 10 second limit
 they gave looks like they intended to do it about this way, but with a
 compiled language.  68 seconds isn't so bad for 4000 entries in pure
 CPython.  Next thing to do I think is use psyco or pyrex.

FWIW, the original program can also be compiled with Shed Skin (http://
mark.dufour.googlepages.com), an experimental (static-)Python-to-C++
compiler, resulting in a speedup of about 8 times for a single test
with 500 tuples. here's a slightly modified version that works with
Shed Skin CVS at least:

import time
t = time.clock()

q,w,e,r,sch,h = [],[],[],[],0,{}

f = open(m33.txt,rt)

n = int(f.readline())

for o in range(n):
   row = [int(x) for x in f.readline().split()]
   q.append(row[0])
   w.append(row[1])
   e.append(row[2])
   r.append(row[3])

f.close()

for x in q:
   for y in w:
 if h.has_key(x+y):
   h[x+y] += 1
 else:
   h[x+y] = 1

for x in e:
   for y in r:
 sch += h.get(-(x+y),0)

print sch
print time.clock() - t


Thanks,
Mark Dufour (Shed Skin author - send me bug reports!)

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


running python on xp command prompt

2007-03-17 Thread TPhung
Hi,

I have a simple question about running python on windows xp command
prompt. The file is as follows and is named spam.py:

print 2**8
print 'the bright side' + 'of life'
print hello world

I run this on the command prompt as follows

C:\Documents and Settings\Userpython C:\Documents and Settings\User
\Desktop\spa
m.py
python: can't open file 'C:\Documents': [Errno 2] No such file or
directory

and get the error above. If I surround the second directory in quotes
like this

C:\Documents and Settings\Userpython C:\Documents and Settings\User
\Desktop\spa
m.py

, there is no error. Does anyone know why this is.

Thank you

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


Re: running python on xp command prompt

2007-03-17 Thread Steve Potter
On Mar 17, 2:15 pm, [EMAIL PROTECTED] wrote:
 Hi,

 I have a simple question about running python on windows xp command
 prompt. The file is as follows and is named spam.py:

 print 2**8
 print 'the bright side' + 'of life'
 print hello world

 I run this on the command prompt as follows

 C:\Documents and Settings\Userpython C:\Documents and Settings\User
 \Desktop\spa
 m.py
 python: can't open file 'C:\Documents': [Errno 2] No such file or
 directory

 and get the error above. If I surround the second directory in quotes
 like this

 C:\Documents and Settings\Userpython C:\Documents and Settings\User
 \Desktop\spa
 m.py

 , there is no error. Does anyone know why this is.

 Thank you

It is because of the spaces in the path.  The command prompt assumes
that when it encounters a space that is the end of the attribute.  By
surrounding it in quotes you are indicating that it is all one
attribute.


Steve

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


Re: SQLite3, data not found

2007-03-17 Thread jim-on-linux
On Saturday 17 March 2007 13:51, John Nagle wrote:
 jim-on-linux wrote:
  On Friday 16 March 2007 18:23, Jerry Hill 
wrote:
 On 3/16/07, jim-on-linux
  [EMAIL PROTECTED]
 
  wrote:
 Below, the first select produces results
  but, after closing then re-opening the
  database the select produces an empty list.
   Anyone know the reason ??
 
 When you first open a connection, you
 implicitly begin a transaction. You need to
 call con.commit() before you close the
 connection, or your transaction will be
  rolled back when you close() it.  If don't
  want to bother with transaction handling,
  you can turn it off when you open the
  connection, like this: con =
  sqlite3.connect('myData',
 isolation_level=None)
 
 See the Python Database API 2.0 PEP for more
 details about the behavior required of DB-API
 2.0 compliant interfaces:
 http://www.python.org/dev/peps/pep-0249/
 
 --
 Jerry
 
  Thanks, this saves a lot of con.commit
  action. And the website is valuable.
 
  jim-on-linux

 Don't turn off atomic transactions, use
 them. Otherwise, two copies of your program
 running at the same time will probably not do
 what you want. Just call commit at the end of
 each transaction.

   John Nagle

Thanks 
I appreciate the help.

jim-on-linux






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


Pickle and Instance Methods

2007-03-17 Thread Steve Potter
I have a class that I am trying to pickle.   One of the attributes is
used to set a callback e.g.
self.attribute.setCallback(self.callbackfunction).
I understand that this cannot be saved by pickle.
My question is, is there another way of setting a callback that would
agree with pickle?
If not is there some way to make pickle ignore the problem attribute?


Thanks,

Steve

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


Re: Pickle and Instance Methods

2007-03-17 Thread Troy Melhase
 I understand that this cannot be saved by pickle.
 My question is, is there another way of setting a callback that would
 agree with pickle?
 If not is there some way to make pickle ignore the problem attribute?

Try adding a __getstate__ method to your class:

http://docs.python.org/lib/pickle-inst.html
-- 
http://mail.python.org/mailman/listinfo/python-list


class question

2007-03-17 Thread sittner
Hello there,
i am pretty new to object-oriented programming and i have a question:
let's say i have a simple class such as:
class father:
 age=...
 name=
 def abcd.
 class son(father):
age=
name=
def efgh:
or any other heirarchic structure of class and subclasses.
i would like to list or print the data content of a given instance of the
subclass, all the way up (e.g. if sam is jack's son, so i would like to
get their names and ages and use the class as a data structure for that
matter).
how do i do this?
thanks,
t

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


Re: distributing python software in jar like fashion

2007-03-17 Thread Colin J. Williams
ce wrote:
 On Mar 15, 10:23 am, alf [EMAIL PROTECTED] wrote:
 Hi,

 I have a small app which consist of a few .py files. Is there any way to
 distribute it in jar like fashion as a single file I can just run python
 on. I obviously look for platform independent solution.

 Thx in advance, A.
 
 You can import from zip achieves as PEP 273, but to execute in the
 same mechanism as the jar files, recently there is no way afaik.
You could treat the collection of files as a Python package.  You would 
then add an __init__.py file to your collection and, in that __init__.py 
arrange to initiate main.py (or  whatever you call your initiator program).

Colin W.
 
 ce (pain n d'ass)
 

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


Re: Weekly Python Patch/Bug Summary

2007-03-17 Thread Robert Kern
Terry Reedy wrote:
 Dick Moores [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 | I thought I'd give
 | http://svn.python.org/projects/python/branches/release25-maint/
 | (the latest release (plus bug fixes) of Python) a try. I first backed
 | up my Python25 folder (I'm using Win XP). Then with Python 25 open I
 | opened the Explorer context menu for the folder and then the
 | TortoiseSVN sub-menu. There doesn't seem to have a menu item that
 | will enable me to update. I tried Export... and entered
 | http://svn.python.org/projects/python/branches/release25-maint/ as
 | URL of repository, but that choice seems to expect the Python25
 | folder to be empty. Can you tell me what to do to just update?
 
 Just to make sure you know, the svn repository is source code that you will 
 have to compile.  If TortoiseSVN only copies repositories and reads and 
 does not update, then you need svn itself.  But I know almost nothing about 
 it except the name.

It's a fully-functional SVN client. It can update.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Automagically log changes in table

2007-03-17 Thread George Sakkis
This is more in the context of Turbogears/SQLAlchemy, but if anyone
has implemented something similar with other packages it might be
useful to know.

I'd like to have a way to make a table loggable, meaning it would
get, say, two fields last_modified and modified_by, and every
write operation on it would automatically record the time and the id
of the user who did the addition or change (I'm not sure how to deal
with deletions let's leave this for now). Has anyone done something
like that or knows where to start from ?

George

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


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread bearophileHUGS
Mark Dufour:
 FWIW, the original program can also be compiled with Shed Skin (http://
 mark.dufour.googlepages.com), an experimental (static-)Python-to-C++
 compiler, resulting in a speedup of about 8 times for a single test
 with 500 tuples.

If we want to play, then this is a literal translation to D (I am not
much good in D yet, so maybe there are ways to improve this code a
bit), as you can see D syntax isn't that bad (I think sometimes D
copies some Python syntax):


// Compile with:   dmd -O -release solver.d
import std.stdio, std.stream, std.string;

void main() {
size_t sch;
size_t[size_t] h;
size_t[] q,w,e,r;

int nrow = -1;
auto datafile = new File(m4000.txt, FileMode.In);
foreach(char[] row; datafile) {
if (nrow == -1) {
q.length = row.atoi();
w.length = row.atoi();
e.length = row.atoi();
r.length = row.atoi();
} else {
char[][] srow = row.split();
q[nrow] = srow[0].atoi();
w[nrow] = srow[1].atoi();
e[nrow] = srow[2].atoi();
r[nrow] = srow[3].atoi();
}
nrow++;
}

foreach (x; q)
foreach (y; w)
h[x+y]++;

foreach (x; e)
foreach (y; r) {
size_t* pointer = -x-y in h;
if (pointer)
sch += *pointer;
// simpler but slower:
// if (-x-y in h)
// sch += h[-x-y];
}

writefln(sch);
}


On my PC with the 1000 lines file this is about 2.2 times faster than
my  Psyco version and about 4.6 times faster than the same code
without Psyco.

Bye,
bearophile

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


Re: Returning other instance from __init__ - I need help

2007-03-17 Thread Paulo da Silva
Gabriel Genellina escreveu:
 En Fri, 16 Mar 2007 22:05:05 -0300, Paulo da Silva
 [EMAIL PROTECTED] escribió:
...

 class C(object):
 
 def __new__(cls, filename=None, foo=None, bar=None):
 if filename is not None:
 return cls.load(filename)
 inst = super(C, cls).__new__(cls)


This makes the difference! I didn't know how to build an
instance inside __new__.

Thank you very much Gabriel.
Paulo
-- 
http://mail.python.org/mailman/listinfo/python-list


Still the __new__ hell ...

2007-03-17 Thread Paulo da Silva
Sorry to put here too many questions about __init__ __new__
stuff but I always found a new problem when using them.
I have searched for simple __new__ docs on how to do the
basic things but find none.

After trying the solutions people gently posted here
(thanks) I run into new trouble when I go with further
development.

Here is the new situation.

As suggested in a previous post, I used __new__ to
subclass date class but now cPickle/pickle loads
does not work.

from datetime import date
import cPickle,string

class MyDate(date):
def __new__(cls,year,month=None,day=None):
if type(year) is str:
year,month,day=map(int,string.split(year,'-'))
if year100:
year+=2000
return date.__new__(cls,year,month,day)

class C1(object):
def __init__(self):
self.x=MyDate(2007-3-15)

def f(self):
print self.x

c1=C1()

d=cPickle.dumps(c1)
c2=cPickle.loads(d)
c2.f()

1. year is passed to __new__ as a string but with invalid
contents!

2. If I had a __new__ in class C1, cPickle.loads invokes it
with only one parameter. This forces to allow __new__ accept
only 1 parameter (cls) which I don't want for the normal
situation.

Thanks for your patience.
Paulo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Still the __new__ hell ...

2007-03-17 Thread Arnaud Delobelle
On Mar 17, 9:31 pm, Paulo da Silva [EMAIL PROTECTED] wrote:
 Sorry to put here too many questions about __init__ __new__
 stuff but I always found a new problem when using them.
 I have searched for simple __new__ docs on how to do the
 basic things but find none.

 After trying the solutions people gently posted here
 (thanks) I run into new trouble when I go with further
 development.

 Here is the new situation.

 As suggested in a previous post, I used __new__ to
 subclass date class but now cPickle/pickle loads
 does not work.

 from datetime import date
 import cPickle,string

 class MyDate(date):
 def __new__(cls,year,month=None,day=None):
 if type(year) is str:
 year,month,day=map(int,string.split(year,'-'))
 if year100:
 year+=2000
 return date.__new__(cls,year,month,day)

 class C1(object):
 def __init__(self):
 self.x=MyDate(2007-3-15)

 def f(self):
 print self.x

 c1=C1()

 d=cPickle.dumps(c1)
 c2=cPickle.loads(d)
 c2.f()

I haven't tried your code but I think that you may need to define a
__reduce__ method in your MyDate class in order to give a clue to the
python as to how to pickle its instances.  For more details see:

http://docs.python.org/lib/node321.html

Something like:

class MyDate(date):
...
def __reduce__(self):
return type(self), (self.year, self.month, self.day)

might solve your problem.

HTH

--
Arnaud

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


Re: Still the __new__ hell ...

2007-03-17 Thread Paul McGuire
On Mar 17, 4:31 pm, Paulo da Silva [EMAIL PROTECTED] wrote:
 Sorry to put here too many questions about __init__ __new__
 stuff but I always found a new problem when using them.
 I have searched for simple __new__ docs on how to do the
 basic things but find none.

 After trying the solutions people gently posted here
 (thanks) I run into new trouble when I go with further
 development.

 Here is the new situation.

 As suggested in a previous post, I used __new__ to
 subclass date class but now cPickle/pickle loads
 does not work.

 from datetime import date
 import cPickle,string

 class MyDate(date):
 def __new__(cls,year,month=None,day=None):
 if type(year) is str:
 year,month,day=map(int,string.split(year,'-'))
 if year100:
 year+=2000
 return date.__new__(cls,year,month,day)

 class C1(object):
 def __init__(self):
 self.x=MyDate(2007-3-15)

 def f(self):
 print self.x

 c1=C1()

 d=cPickle.dumps(c1)
 c2=cPickle.loads(d)
 c2.f()

 1. year is passed to __new__ as a string but with invalid
 contents!

 2. If I had a __new__ in class C1, cPickle.loads invokes it
 with only one parameter. This forces to allow __new__ accept
 only 1 parameter (cls) which I don't want for the normal
 situation.

 Thanks for your patience.
 Paulo

Any special reason you have to use __new__ for this factory method?
This version works, without the problems with __new__:

def getDate(*args):
if isinstance(args[0],basestring):
year,month,day = map(int,string.split(args[0],'-'))
else:
year,month,day = args
if year  100:
year += 2000
return date(year,month,day)

class C1(object):
def __init__(self):
#self.x=MyDate(2007-3-15)
self.x = getDate(2007-3-15)

def f(self):
print self.x


-- Paul

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


Re: class question

2007-03-17 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
 Hello there,
 i am pretty new to object-oriented programming and i have a question:
 let's say i have a simple class such as:
 class father:
  age=...
  name=
  def abcd.
  class son(father):
 age=
 name=
 def efgh:
 or any other heirarchic structure of class and subclasses.
 i would like to list or print the data content of a given instance of the
 subclass, all the way up (e.g. if sam is jack's son, so i would like to
 get their names and ages and use the class as a data structure for that
 matter).

You misunderstand Python's classes.  There is little, if any advantage
to defining a class inside another class.

How about:
 import weakref  # to keep everyone from being immortal.

 class Person(object):
 def __init__(self, age, name, dad=None, mom=None):
 self.name = name
 self.age = age
 self.dad = dad
 self.mom = mom
 self._kids = weakref.WeakValueDictionary()
 if dad is not None:
 dad.add_kid(self)
 if mom is not None:
 mom.add_kid(self)

 def children(self):
 return self._kids.values()

 def add_kid(self, child):
 assert self.age  child.age
 self._kids[id(child)] = child

 def __repr__(self):
return '%s(%s)' % (self.name, self.age)

 guy = Person(age=28, name='George')
 gal = Person(age=31, name='Martha')
 kid = Person(age=1, name='Ellen', dad=guy, mom=gal)
 print '%s of %s and %s.' % (kid, kid.dad, kid.mom)
 print %s's kids: %s. % (guy, guy.children())
 print %s's kids: %s. % (gal, gal.children())

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


[ANN] squisher 0.3

2007-03-17 Thread Adam Atlas
http://cheeseshop.python.org/pypi/squisher/0.3

I've posted the third version of my experimental packaging program
Squisher. Squisher can take a directory representing a Python package
(i.e. a directory with __init__.py) and squish it into a single .pyc
file that you can import, or run on the command line, just like any
other .py/.pyc file.

The hook is that it can be thus imported *without* necessarily having
Squisher itself installed. All you do is run Squisher on a directory
(or an existing zip file if you wish), and you get a single file you
can import with any normal Python installation.

It is complementary to Eggs in a way. They're good for having packages
globally installed and keeping them up-to-date, but very often you may
want the simple convenience of dropping a .pyc in a directory and
importing it. Furthermore, since Squished packages are just zip files
with a special Python bytecode header (and Eggs are just zipfiles with
internal metadata added), you can actually run it on an Egg and get a
file that can be used as an Egg *or* a Squished package just by
renaming it.

Try it out... I've found it useful so far. It is still pretty
experimental, so I wouldn't advise using it as a serious packaging
mechanism yet, but I hope that with time it will become very stable
and complete. Bug reports/patches welcome.

--

Changelog for anyone who tried the previous releases:
- Added a couple of patches courtesy of Gary Duzan -- a Python 2.3
compatibility fix, and a fix for importing compiled modules when
running a .pyc from the command line.
- Changed from GPL to BSD license. Also clarified that the generated
bytecode is considered public domain.
- It now detects if you pass it an already-squished module -- if so,
it will simply update the bytecode header if necessary.

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


MIME Magic

2007-03-17 Thread Samuel
Hi,

How can I determine the type of a file from magic bytes, similar to
what the file command on unix does? I found

http://docs.python.org/lib/module-mimetypes.html

but this only seems to use the filename (extension) for finding the
type. Any hints?

-Samuel

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


formatting strings to have the same width

2007-03-17 Thread spohle
hi,

i got random strings and wanna attach a  |   at the end. now if i
print them i want the | to always be underneath each other. example
code:

foo = [aaa, 1232]
for each in foo:

print foo[0].center(10,  ) +  | 
foo2 = 1232
print foo2.center(10,  ) +  | 

even though i define a constant width on the strings the | don't show
up underneath each other.
any ideas ?

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


Re: formatting strings to have the same width

2007-03-17 Thread spohle
sorry the code should read:

foo = [aaa, 1232]
for each in foo:
print each.center(10,  ) +  | 

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


Re: MIME Magic

2007-03-17 Thread Jorge Godoy
Samuel [EMAIL PROTECTED] writes:

 Hi,

 How can I determine the type of a file from magic bytes, similar to
 what the file command on unix does? I found

 http://docs.python.org/lib/module-mimetypes.html

 but this only seems to use the filename (extension) for finding the
 type. Any hints?

I'd start by taking a look at file's code. :-)

The thing is being able to identify the signatures of several different types
of files.  Here's some help for you:
http://www.garykessler.net/library/file_sigs.html

And here's an example of an authoritative source for that table:
http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html 



-- 
Jorge Godoy  [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Report options...

2007-03-17 Thread Mario Lacunza
Hello,

Right now Im migrating an VB6+Crystal report+Word App to Python+wxPython
+Reportlab+???

The VB system work with Word creating some patterns (title, foot prints,
etc) and users maybe could insert some Forms fields to personalize the
output connecting this fields with an recordset.

I dont want to use any external tool for this taks (OpenOffice+pyUno is
my last chance)

Any suggestion?

Thanks!

Mi configuracion/My config:

Ubuntu Edgy Eft 6.10
Linux Kernel 2.6.17-11-386
Gnome 2.16.1
Python 2.4.4c1
wxPython 2.8.1.1 Unicode
Python IDE: Ulipad 3.6
Database: Firebird 2.0 Superserver

-- 
Saludos / Best regards 

Mario Lacunza Vásquez 
Desarrollador de Software - Webmaster
Linux Registered User #439179 
Desarrollador 2 Estrellas VS2005

Website: http://mlacunzav[DOT]cogia[DOT]net 
Email  : mlacunza[AT]gmail.com / mario_lacunza[AT]yahoo.es
Blog   : http://mlacunza.blogspot.com
Lima - Peru

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

Re: formatting strings to have the same width

2007-03-17 Thread Steven D'Aprano
On Sat, 17 Mar 2007 16:07:44 -0700, spohle wrote:

 hi,
 
 i got random strings and wanna attach a  |   at the end. now if i
 print them i want the | to always be underneath each other. example
 code:
 
 foo = [aaa, 1232]
 for each in foo:
 
 print foo[0].center(10,  ) +  | 
 foo2 = 1232
 print foo2.center(10,  ) +  | 
 
 even though i define a constant width on the strings the | don't show
 up underneath each other.
 any ideas ?

Three possibilities:

(1) Your code is fine, but whatever you are using to display the strings
is wrong because it is using the wrong sort of font.

What font are you using? If it is a proportional font, e.g. Times New
Roman, then each different character is a different width, and counting
characters is not likely to result in equal widths.

e.g. compare these two lines:

mw mw mw mw mw |
il il il il il |

If the vertical bars line up, you're (probably) using a fixed-width font
like Courier. If they're not, you're (probably) using a proportional font
like Ariel or Times.


(2) Your code is fine, but your data is bad. 

You are centering your strings with a width of ten. Is it possible that
some of the strings you are passing into the are longer than ten
characters? If so, you'll get funny results, because str.center() will
never shorten the string you pass it.


(3) You code in Python like you write in English: poorly with lots of
errors. Wanna isn't a word (unless you're trying to be funny), and
capitalization is the difference between:

I helped my Uncle Jack off a horse

and 

I helped my uncle jack off a horse.

After fixing your indentation error, your example code works perfectly
for me. Perhaps your real code is different, and part of the difference
causes the problem? For instance, your example code seems to do something
unlikely to be useful:

foo = [aaa, 1232]
for each in foo:
print foo[0].center(10,  ) +  | 

That prints the FIRST item each time around the loop, instead of each item.

Also, you don't need the second argument to center. By default, space is
used as a fill character.



-- 
Steven.

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


Re: MIME Magic

2007-03-17 Thread Samuel
On Mar 18, 12:30 am, Jorge Godoy [EMAIL PROTECTED] wrote:
 I'd start by taking a look at file's code. :-)

 The thing is being able to identify the signatures of several different types
 of files.  Here's some help for 
 you:http://www.garykessler.net/library/file_sigs.html

 And here's an example of an authoritative source for that 
 table:http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html

Actually, I am looking for an existing solution because I do not want
to write it from scratch... I hope I am not out of options.

-Samuel

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


Re: Still the __new__ hell ...

2007-03-17 Thread Paulo da Silva
Arnaud Delobelle escreveu:
 On Mar 17, 9:31 pm, Paulo da Silva [EMAIL PROTECTED] wrote:
...

 I used __new__ to
 subclass date class but now cPickle/pickle loads
 does not work.

 from datetime import date
 import cPickle,string

 class MyDate(date):
 def __new__(cls,year,month=None,day=None):
 if type(year) is str:
 year,month,day=map(int,string.split(year,'-'))
 if year100:
 year+=2000
 return date.__new__(cls,year,month,day)

 class C1(object):
 def __init__(self):
 self.x=MyDate(2007-3-15)

 def f(self):
 print self.x

 c1=C1()

 d=cPickle.dumps(c1)
 c2=cPickle.loads(d)
 c2.f()
 
 I haven't tried your code but I think that you may need to define a
 __reduce__ method in your MyDate class in order to give a clue to the
 python as to how to pickle its instances.  For more details see:
 
 http://docs.python.org/lib/node321.html
 
 Something like:
 
 class MyDate(date):
 ...
 def __reduce__(self):
 return type(self), (self.year, self.month, self.day)
 
 might solve your problem.
 
 HTH
 
 --
 Arnaud
 

Thanks. This works exactly the way you wrote.
Yet I am misunderstanding something. Can't pickle see that being
MyDate derived from date it also has to look at variables from date?
When do I need to do this? I am using pickle with a lot more complex
classes without this problem.

Thank you
Paulo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automagically log changes in table

2007-03-17 Thread aspineux
Hi

You can get this using triggers and stored procedures.
These are SQL engine dependent! This is available for long time with
postgress and only from version 5 with mysql.
This let you write SQL code (Procedure) that will be called when
trigged by an event like inserting new row, updating rows,
deleting 

BR


On 17 mar, 21:43, George Sakkis [EMAIL PROTECTED] wrote:
 This is more in the context of Turbogears/SQLAlchemy, but if anyone
 has implemented something similar with other packages it might be
 useful to know.

 I'd like to have a way to make a table loggable, meaning it would
 get, say, two fields last_modified and modified_by, and every
 write operation on it would automatically record the time and the id
 of the user who did the addition or change (I'm not sure how to deal
 with deletions let's leave this for now). Has anyone done something
 like that or knows where to start from ?

 George


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


Re: formatting strings to have the same width

2007-03-17 Thread John Machin
On Mar 18, 10:17 am, spohle [EMAIL PROTECTED] wrote:
 sorry the code should read:

 foo = [aaa, 1232]
 for each in foo:
 print each.center(10,  ) +  | 

Works OK for me on the console:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
Type help, copyright, credits or license for more information.
 foo = ['123', '1234', '12345']
 for each in foo:
... print each.center(10, .) +  | 
...
...123 |
...1234... |
..12345... |

 for each in foo:
... print each.center(10,  ) +  | 
...
   123 |
   1234|
  12345|
 for each in foo:
... guff = each.center(10,  ) +  | 
... print guff + str(len(guff))
...
   123 | 13
   1234| 13
  12345| 13


Of course if I go into IDLE and change it to use a proportionally
spaced font (e.g. Arial), and do this:

 foo = ['l', 'm']
 for each in foo:
print each.center(10, ' ') + ' | '


  l|
  m|


naturally they don't line up. If something like that isn't the cause
of your problem, you'll need to provide more information about your
environment.

HTH,
John

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


Re: tkinter grid vs pack

2007-03-17 Thread aspineux
On 18 mar, 16:49, Gigs_ [EMAIL PROTECTED] wrote:
 For what is grid better than pack, and otherwise?

 thanks in advance

Grid are useful to align items vertically _AND_ horizontally !
For example to make adialog box with label of different length

Firstname: John__
Lastname: Smith__
Contry: Uk__

to align vertically Firstname and John , Lastname and Smith 
But ALSO horizontaly John, Smith and Uk !

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


Re: MIME Magic

2007-03-17 Thread aspineux
On 18 mar, 00:54, Samuel [EMAIL PROTECTED] wrote:
 On Mar 18, 12:30 am, Jorge Godoy [EMAIL PROTECTED] wrote:

  I'd start by taking a look at file's code. :-)

  The thing is being able to identify the signatures of several different 
  types
  of files.  Here's some help for 
  you:http://www.garykessler.net/library/file_sigs.html

  And here's an example of an authoritative source for that 
  table:http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html

 Actually, I am looking for an existing solution because I do not want
 to write it from scratch... I hope I am not out of options.

 -Samuel


python-magic : Python binding for the magic library

This Python library can be use to query /etc/magic information for a
given file in Python.


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


How to parse the os.system() output in python

2007-03-17 Thread [EMAIL PROTECTED]
Hi,

I use os.system() to execute a system command in python.
Can you please tell me how can I parse (in python) the output of the
os.system()  ?

Thank you.

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


IDE for wxPython

2007-03-17 Thread Ghirai
Hello python-list,

Can anyone suggest an IDE for wxPython?
Or an IDE for TkInter?

Thanks.

-- 
Best regards,
Ghirai.

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


Looking for a job?

2007-03-17 Thread good_online_jobs
Free. Find a Job here now-- http://www.jobbankdata.com

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


Re: IDE for wxPython

2007-03-17 Thread sleek
On Mar 17, 4:12 pm, Ghirai [EMAIL PROTECTED] wrote:
 Hello python-list,

 Can anyone suggest an IDE for wxPython?
 Or an IDE for TkInter?

 Thanks.

 --
 Best regards,
 Ghirai.

You might want to check out SPE. It's a great Python IDE.
http://pythonide.blogspot.com/

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


Re: How to parse the os.system() output in python

2007-03-17 Thread Dave Reed

On Mar 17, 2007, at 8:28 PM, [EMAIL PROTECTED] wrote:

 Hi,

 I use os.system() to execute a system command in python.
 Can you please tell me how can I parse (in python) the output of the
 os.system()  ?

 Thank you.


Sounds like you want os.popen, not os.system.

http://docs.python.org/lib/module-popen2.html

Dave

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


Webcams and python

2007-03-17 Thread Synt4x
I'm using VideoCapture in windows to obtain images from my webcam. The
thing is, if i want to show a live video from my webcam i have to make
an infinite loop and request an image everytime:

from VideoCapture import Device
cam = Device()

while 1:
img = cam.getImage()

Now, by doing this, my processor fires up to 100% load, which
obviously makes my pc useless.

Is there any way or algorithm to lower the cpu load?

Thx.

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


Re: Automagically log changes in table

2007-03-17 Thread George Sakkis
On Mar 17, 7:59 pm, aspineux [EMAIL PROTECTED] wrote:

 Hi

 You can get this using triggers and stored procedures.
 These are SQL engine dependent! This is available for long time with
 postgress and only from version 5 with mysql.
 This let you write SQL code (Procedure) that will be called when
 trigged by an event like inserting new row, updating rows,
 deleting 

I'd rather avoid triggers since I may have to deal with Mysql 4. Apart
from that, how can a trigger know the current user ? This information
is part of the context (e.g. an http request), not stored persistently
somewhere. It should be doable at the framework/orm level but I'm
rather green on Turbogears/SQLAlchemy.

George

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


Re: IDE for wxPython

2007-03-17 Thread SPE - Stani's Python Editor
On Mar 18, 2:23 am, sleek [EMAIL PROTECTED] wrote:
 On Mar 17, 4:12 pm, Ghirai [EMAIL PROTECTED] wrote:

  Hellopython-list,

  Can anyone suggest an IDE for wxPython?
  Or an IDE for TkInter?

  Thanks.

  --
  Best regards,
  Ghirai.

 You might want to check outSPE. It's a 
 greatPythonIDE.http://pythonide.blogspot.com/

The latest version SPE 0.8.4 is currently only available through
subversion and will hopefully be released on the 1st of april:
svn checkout svn://svn.berlios.de/python/spe/trunk/_spe

Stani
--
http://pythonide.stani.be

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


Re: How to parse the os.system() output in python

2007-03-17 Thread Sebastian Bassi
On 17 Mar 2007 17:28:56 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I use os.system() to execute a system command in python.
 Can you please tell me how can I parse (in python) the output of the
 os.system()  ?

Maybe you mean to parse the output of the program you run using
os.system. If this is the case, you should redirect the putput of the
program to a file (with ) and then parse that file.

Best,
SB.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
bearophileH!

I gave to your oil svrl runs (z in dict instd of dict.has_key
saved only ~0.4 sec).
The result is (and I'm completely lost in all these
*optimizations* :)):


  RESTART ===

0
34.78 secs (bearophileH)
  RESTART ===

0
34.77 secs (bearophileH)
  RESTART ===

0
34.76 secs (bearophileH)
  RESTART ===

0
27.2460938471 secs (n00m)
  RESTART ===

0
27.2953596058 secs (n00m)
  RESTART ===

0
27.3709929614 secs (n00m)




In the name of exactness this is the tested codes:

++
from collections import defaultdict
import time, psyco


def main():
sch = 0
q,w,e,r = [],[],[],[]
h = defaultdict(int)


datafile = file(D:/m4000.txt)
datafile.next()
xrows = (map(int, line.split()) for line in datafile)
q, w, e, r = zip(*xrows)


for x in q:
for y in w:
h[x+y] += 1


for x in e:
for y in r:
if -x-y in h:
sch += h[-x-y]


print sch


t = time.clock()
psyco.full()
main()
print round(time.clock() - t, 2), secs (bearophileH)
++

++
import psyco, time

def main():
  q,w,e,r,sch,h = [],[],[],[],0,{}
  f = open(D:/m4000.txt,rt)
  for o in range(int(f.readline())):
row = map(int, f.readline().split())
q.append(row[0])
w.append(row[1])
e.append(row[2])
r.append(row[3])
  f.close()

  for x in q:
for y in w:
  if (x+y) in h:
h[x+y] += 1
  else:
h[x+y] = 1

  for x in e:
for y in r:
  if -(x+y) in h:
sch += h[-(x+y)]

  q,w,e,r,h = None,None,None,None,None
  print sch

t = time.clock()
psyco.full()
main()
print time.clock() - t,secs (n00m)
++

PS Both Python  Psyco of 2.5 ver.

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


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
my dial-up line's too slow for downloading 4mb of shedskin-0.0.20.exe

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


List to string

2007-03-17 Thread Hitesh

Hi,

I've a list like this..
str1 = ['this is a test string inside list']

I am doing it this way.

for s in str1:
temp_s = s
print temp_s

Any better suggestions?

Thank you,
hj

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


Re: How to parse the os.system() output in python

2007-03-17 Thread bruce peng
how to redirect the putput of the
program to a file?

thanks.
Sebastian Bassi [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On 17 Mar 2007 17:28:56 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] 
 wrote:
 I use os.system() to execute a system command in python.
 Can you please tell me how can I parse (in python) the output of the
 os.system()  ?

 Maybe you mean to parse the output of the program you run using
 os.system. If this is the case, you should redirect the putput of the
 program to a file (with ) and then parse that file.

 Best,
 SB. 


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


Re: List to string

2007-03-17 Thread Hitesh
On Mar 18, 12:28 am, Hitesh [EMAIL PROTECTED] wrote:
 Hi,

 I've a list like this..
 str1 = ['this is a test string inside list']

 I am doing it this way.

 for s in str1:
 temp_s = s
 print temp_s

 Any better suggestions?

 Thank you,
 hj

I want to cast value of a list into string..

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


Re: How to parse the os.system() output in python

2007-03-17 Thread Sebastian Bassi
On 3/18/07, bruce peng [EMAIL PROTECTED] wrote:
 how to redirect the putput of the
 program to a file?

like this:
program_name -parameters  outfile.txt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List to string

2007-03-17 Thread Steven D'Aprano
On Sat, 17 Mar 2007 21:28:56 -0700, Hitesh wrote:

 
 Hi,
 
 I've a list like this..
 str1 = ['this is a test string inside list']

That's a bad name for the variable. It's called str1 but it is a list.


 I am doing it this way.
 
 for s in str1:
 temp_s = s
 print temp_s

That's redundant. Why not just print s? That will work perfectly.


You can do any of the following, depending on what you are trying to do.


my_list = [first string, second string, third string]

# print the entire list as a string
print my_list

# print each string individually
for s in my_list:
print s

# save the string representation of the entire list as a variable
my_str = repr(my_list)
another_str = str(my_list)

Note that repr() and str() may have different results, depending on the
type of object you pass into them.


# extract the first string into another variable
my_str = my_list[0]

# insert the third string into another string
my_string = This is the %s here. % my_list[2]


Hope that helps.


-- 
Steven.

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


[ANN] GCC 4.1.2 installer for Python distutils compilation

2007-03-17 Thread Giovanni Bajo
Hello,

This page:
   http://www.develer.com/oss/GccWinBinaries

contains a friendly Windows installer for GCC 4.1.2 (MinGW binary version), 
with full support for integrating it with Python installations so that it is 
used by distutils to compile Python extensions.


Direct download link:
   http://www.develer.com/~rasky/gcc-4.1.2-mingw-setup.exe


Who needs this package?

  * People who wants to use FLOSS tools to develop Python extensions.
  * People who wants to use the recent GCC 4.1.2 to develop Python extensions, 
given that it easily outperforms the 4-years-old Visual Studio .NET 2003.


What's special about this?

  * mingw.org still has GCC 3.4.2, so go figure. Also, you need to compose 
other packages together. This is a single installer with everything inside.
  * By default, MinGW GCC links with MSVCRT.DLL, and not MSVCR71.DLL (used by 
Python 2.4 and 2.5). Fixing this is pretty complicate, and there's much 
confusion (Google turns up red herrings). This package handles everything for 
you, and it just works.

-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
  RESTART ===

0
30.4740708665 secs (Anton Vredegoor)
  RESTART ===

0
30.4132625795 secs (Anton Vredegoor)
  RESTART ===

0
30.4812175849 secs (Anton Vredegoor)



+++
import psyco, time

def freq(L):
  D = {}
  for x in L:
  D[x] = D.get(x,0)+1
  return D

def test():
 f = file('D:/m4000.txt')
 f.readline()
 L = []
 for line in f:
 L.append(map(int,line.split()))

 q,w,e,r = map(freq,zip(*L))
 sch,h = 0,{}
 for xk,xv in q.iteritems():
   for yk,yv in w.iteritems():
 if h.has_key(xk+yk):
   h[xk+yk] += xv*yv
 else:
   h[xk+yk] = xv*yv

 for xk,xv in e.iteritems():
   for yk,yv in r.iteritems():
 if h.has_key(-(xk+yk)):
   sch += h[-(xk+yk)]*xv*yv

 print sch

t = time.clock()
psyco.full()
test()
print time.clock() - t,secs (Anton Vredegoor)
+++

PS
The same PC: AMD Sempron +2600 (1.6 GHz); 512 MB RAM.

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


[ python-Bugs-1681671 ] Python and Indeterminate Forms (Math)

2007-03-17 Thread SourceForge.net
Bugs item #1681671, was opened at 2007-03-15 12:28
Message generated for change (Comment added) made by josiahcarlson
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1681671group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: jehahn (jehahn)
Assigned to: Nobody/Anonymous (nobody)
Summary: Python and Indeterminate Forms (Math)

Initial Comment:
Primary example:

Python 2.3.5 (#1, Mar 20 2005, 20:38:20) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type help, copyright, credits or license for more information.
 0 ** 0
1

Per http://mathworld.wolfram.com/Indeterminate.html, 0 ** 0 is an indeterminate 
form. 0 ** 0 should probably return NaN and NOT 1.

Other examples include:

Python 2.3.5 (#1, Mar 20 2005, 20:38:20) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type help, copyright, credits or license for more information.
 inf = float(infinity)
 inf ** 0
1.0
 1 ** inf
1.0

For a few others, Python provides an arguably correct answer of NaN. Examples:

Python 2.3.5 (#1, Mar 20 2005, 20:38:20) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type help, copyright, credits or license for more information.
 inf = float(infinity)
 inf * 0
nan
 inf / inf
nan
 inf - inf
nan

And, of course, for the most obvious indeterminate form (0/0) Python does 
precisely the right thing:

Python 2.3.5 (#1, Mar 20 2005, 20:38:20) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type help, copyright, credits or license for more information.
 0/0
Traceback (most recent call last):
  File stdin, line 1, in ?
ZeroDivisionError: integer division or modulo by zero

It could be argued that the correct thing to do here is to throw an exception - 
mathematically speaking these forms are about as meaningful as division by zero 
which Python handles by throwing an exception. (unlike Java and  IEEE 754, 
which do arguably evil things here by returning +/- infinity for the quantity 
k/0 for all k != 0)

Unfortunately, some people doing numerical work may have gotten used to the 
current Python behavior so the change isn't without risk. And some of the 
current values are common conventions used to simplify certain common issues. 
(e.g. 0 ** 0 == 1) Moreover, I don't know if this is dependent on platform 
(having only tried it on a couple of the boxes I have handy.) 

However, from a mathematical purist's standpoint, Python is doing the wrong 
thing on these counts.

--

Comment By: Josiah Carlson (josiahcarlson)
Date: 2007-03-17 01:20

Message:
Logged In: YES 
user_id=341410
Originator: NO

Python's behavior with respect to floating point arithmetic is left to the
platform's C floating point libraries.  For example, on my Windows machine
running Python 2.3.5, float(infinity) raises a ValueError.  I would also
point out that 0/0 is integer division in Python 2.3.5 .

For other examples of platform-specific behavior:
Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on
win32
Type help, copyright, credits or license for more information.
 inf*0
-1.#IND
 inf**0
1.0
 1**inf
Traceback (most recent call last):
  File stdin, line 1, in ?
ValueError: (33, 'Domain error')
 inf*0
-1.#IND
 inf/inf
-1.#IND
 inf-inf
-1.#IND


So yeah.  If you don't like how Python does math, complain to your vendor
(Apple) or compile a version of Python with a C floating point library that
works the way you want it to.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1681671group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1682729 ] Documentation error (section 3.4.1)

2007-03-17 Thread SourceForge.net
Bugs item #1682729, was opened at 2007-03-17 15:03
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1682729group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Documentation
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: emlyn (emlyncorrin)
Assigned to: Nobody/Anonymous (nobody)
Summary: Documentation error (section 3.4.1)

Initial Comment:
In the documentation section 3.4.1 Basic customization (url: 
http://docs.python.org/ref/customization.html) it states:

There are no reflected (swapped-argument) versions of these methods (to be used 
when the left argument does not support the operation but the right argument 
does); rather, __lt__() and __gt__() are each other's reflection, __le__() and 
__ge__() are each other's reflection, and __eq__() and __ne__() are their own 
reflection.

Surely that should be __lt__() and __ge__() are each other's reflection, and 
__le__() and __gt__(). I assume this is just a typo, but I haven't checked that 
Python itself gets it right.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1682729group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1682749 ] next method assignment is ignored in new-style classes

2007-03-17 Thread SourceForge.net
Bugs item #1682749, was opened at 2007-03-17 15:06
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1682749group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Albert Weichselbraun (albert2611)
Assigned to: Nobody/Anonymous (nobody)
Summary: next method assignment is ignored in new-style classes

Initial Comment:
in old-style classes the next method of an iterator-superclass can be 
overwritten using

self.next = self.new_next_method

when new-style classes are used the assignment is ignored and instead of 
new_next_method the next method of the superclass is called when the class is 
used as iterator (tested for python2.3-2.5 under debian/linux).
- if the next() method is called directly, the assigned
  method is used (see attached code example).


--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1682749group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >