Fwd: Cisco's $100,000 Developer Contest

2008-11-06 Thread Guido van Rossum
This seems of interest to Python developers all over the world.
Develop a Python app to run on a Cisco router and win real money!

--Guido

-- Forwarded message --
From: Guido van Rossum [EMAIL PROTECTED]
Date: Thu, Nov 6, 2008 at 1:14 PM
Subject: Re: For Guido van Rossum: Cisco's $100,000 Developer Contest
To: Nicole Dawley [EMAIL PROTECTED]


Hey Nicole, I'll forward this to some mailing lists and write a brief
blog entry about it. Thanks for letting me know!

--Guido

On Thu, Nov 6, 2008 at 1:06 PM, Nicole Dawley [EMAIL PROTECTED] wrote:
 Hello Guido,



 I'm writing to introduce myself and let you know about Cisco's $100,000
 Developer Contest.  The contest is for programs written in C, Java, Python,
 Bash or Perl on top of the Cisco's ISR router.



 There's some pretty forward stuff that can be done with these routers; in
 particular, the development platform for the ISR has a Linux kernel and all
 the application processes are isolated, so there's no need to worry about
 memory runaway, etc. The best part is that the first phase doesn't require
 any coding.



 The contest hasn't gotten much press yet and, although I can't guarantee
 anything, the competition is slim at this point so there's a strong
 opportunity for an individual coder or team to make an impact.



 If you find the contest interesting, I hope you'll consider writing an
 article about it for your site.  I think it's a killer opportunity for you
 or your readers and we really need the help of people like you, who are
 connected in the developer community, to get the word out!  I can also
 easily arrange for an interview with a Cisco geek (or most other PR ideas
 you can imagine) so please let me know if that interests you as well.



 You can visit cisco.com/go/thinkinside for more details (we're also on
 Facebook, et al). Also, listen to TechwiseTV stars Robb Boyd and Jimmy Ray
 Purser chat about this exciting opportunity here:
 youtube.com/watch?v=RrqTv3MkIHI. Feel free to post the video if you'd like.



 Sincere thanks for your consideration,



 Nicole Dawley





 ___
 Nicole Dawley
 Social Media Marketing Manager
 M80 | 2894 Rowena Ave. | Los Angeles, CA 90039
 e: [EMAIL PROTECTED] | p: 323.644.7800 x 233 l f: 323.644.7801



 Subscribe to the RSS feed on M80's Newsroom Asset Blog:

 http://m80im.com/newsroom/







--
--Guido van Rossum (home page: http://www.python.org/~guido/)



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: subprocess and PPID

2008-11-06 Thread Michele Petrazzo

Lawrence D'Oliveiro wrote:

In message [EMAIL PROTECTED], Michele Petrazzo
wrote:


I have a code that execute into a Popen a command (ssh). I need
that, if the python process die, the parent pid (PPID) of the child
don't become 1 (like I can seen on /proc/$pid$/status ), but it has
to die, following it's parent It's possible in linux and with
subprocess?


There is a Linux-specific system call that says it does this (haven't
 tried). See the prctl(2) man page.


Just seen. It can be, bust since I cannot modify the child process and
this syscall must be called from the child, I cannot use it.

Thanks,
Michele
--
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess and PPID

2008-11-06 Thread Michele Petrazzo

[EMAIL PROTECTED] wrote:

It's possible in linux and with subprocess?



AFAIK, there is no easy way to do this. If the parent python process 
is doing a controlled exit, just kill the child via close() on

Popen() handle.


Like I do ;)

If the parent is doing a uncontrolled exit (say via a SIGKILL 
signal), you can't really do anything.




The only thing that I thought it's to use an external resource, like a
.pid file where I save the child pid(s) and, on the next parent startup
control the file and kill the process, if any


To reliably have the child exit when the parent exits, you would have
 to poll for the parent from the child and do a exit when the child 
detects that the parent has gone away.




Like said, I haven't the control of the sources, so I can't.

Thanks,
Michele
--
http://mail.python.org/mailman/listinfo/python-list


(Windows) Dropping stuff onto a Python script

2008-11-06 Thread daniel . haude
Hello people,

I'd like to have the functionality known from real executables that
if I drag-drop a file icon on top of the app, the app starts and has
the file's path as command-line argument.

However, this doesn't seem to work with Python scripts because Windows
sees those just as files, not apps.

Can this be done?

Thanks,

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


contextlib.nested()

2008-11-06 Thread brasse
Hello!

I have been running in to some problems when using
contextlib.nested(). My problem arises when using code similar to
this:

from __future__ import with_statement

from contextlib import nested

class Foo(object):

def __init__(self, tag, fail=False):
print 'ctor', tag
self.tag = tag
if fail:
raise Exception()

def __enter__(self):
print '__enter__', self.tag
return self

def __exit__(self, *args):
print '__exit__', self.tag

with nested(Foo('a'), Foo('b', True)) as (a, b):
print a.tag
print b.tag

Here the construction of b fails which in turn means that the
contextmanager fails to be created leaving me a constructed object (a)
that needs to be deconstructed in some way. I realize that nested() is
in a tight spot here to do anything about it since it doesn't exist.
This behavior makes it hard for me to use the with statement (using
nested()) the way I want.

Has anyone else been running in to this? Any tips on how to handle
multiple resources?

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


Re: (Windows) Dropping stuff onto a Python script

2008-11-06 Thread Tim Golden

[EMAIL PROTECTED] wrote:

Hello people,

I'd like to have the functionality known from real executables that
if I drag-drop a file icon on top of the app, the app starts and has
the file's path as command-line argument.

However, this doesn't seem to work with Python scripts because Windows
sees those just as files, not apps.

Can this be done?


There may be fancier ways but...

... prefix the shortcut target with the python executable:

c:\python25\python.exe myscript.py

I've just tested this with a script which does this:

code
import os, sys

os.startfile (sys.argv[1])

/code

and it works ok.

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


Re: How to build the pysqlite? Where to find the sqlite3.h?

2008-11-06 Thread Thorsten Kampe
* Kurda Yon (Wed, 5 Nov 2008 17:52:08 -0800 (PST))
 On Nov 5, 1:55 pm, Thorsten Kampe [EMAIL PROTECTED] wrote:
  You (and Kurda) keep on talking the wrong stuff. First: you don't
  need pysqlite2. SQLite support is included in the latest Python as
  module sqlite3.
 
 By the way, I think the above statement is very helpfull. I tried to
 install the pysqlite to be able to communicate with the sqlite,
 and then I have realized that for that I need first to install the
 sqlite...
 
 But I read your statement and understood that I do not need to install
 neither pysqlite no sqlite. In my Python session I tried to type
 from sqlite import connect and it does not compaline. It meand that
 Python see the database!!! I hope.

I don't think so. There is no sqlite module in Python so the above 
line should give you an error. The module is called sqlite3.
 
 By the where can I find a simle tutorial about the work with the
 sqlite from the Python?

Guess where: in the Python documentation and on the pysqlite web site:
http://docs.python.org/library/sqlite3.html
http://oss.itsystementwicklung.de/download/pysqlite/doc/sqlite3.html

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


Re: developing python extensions with CDT and Pydev in Eclipse

2008-11-06 Thread Fabio Zadrozny
 I have tried all of those things (on Linux), but without success. Has anyone
 tried
 this under Linux?


Have you asked on CDT? (the basic idea is that python behaves as a
regular program launched, so, that should be something straightforward
to do).

Cheers,

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


Re: How to build the pysqlite? Where to find the sqlite3.h?

2008-11-06 Thread Thorsten Kampe
* Shawn Milochik (Wed, 5 Nov 2008 14:32:15 -0500)
 On Wed, Nov 5, 2008 at 1:55 PM, Thorsten Kampe
  You (and Kurda) keep on talking the wrong stuff. First: you don't
  need pysqlite2. SQLite support is included in the latest Python as
  module sqlite3.
 
  If for whatever reason you need the latest SQLite module for Python
  (2.5.0), you can simply grab an rpm or build it from source and
  install it to your home directory. To build pysqlite you need the
  SQLite headers. If you can't install those to default path then
  simply grab the headers, put them somewhere into your home directory
  and tell the pysqlite build process where to find them.
 
 Okay, sorry if I haven't been specific enough. I don't know about the
 original poster, but on the box I'm using, I don't have the latest
 Python, the make command breaks because the system doesn't have the
 proper libraries, and there is no sqlite3 module. I am not authorized
 to fix any of that, and our support team isn't interested in helping
 me because it's a Perl shop, not Python.
 
 I'm not demanding that anyone solve my problem. I'm just asking if
 there are files I can download and without compiling or building them
 in any way, put them somewhere, point Python to that path, and be able
 to use sqlite from Python.

I more or less answered that already: you can grab a rpm for the same 
Python version as you already have, unpack it and put the sqlite3 
support files somewhere into your home directory (~/bin/python/site-
packages for example). If your Python is older than 2.5 then you have to 
download the pysqlite rpms for your distribution and do the same as 
above. To have Python find the modules you have to set the PYTHONPATH 
environment variable. See the man page.

If your distribution doesn't provide RPMs for pysqlite then you have to 
build it yourself. You have to grab the SQLite headers (they are in the 
SQLite RPM probably), unpack them somewhere into your home directory and 
tell the pysqlite build process where to find them. I don't exactly know 
how but this is probably very easy to find out.

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


Re: Extract frame from wmv

2008-11-06 Thread Martin

Lawrence D'Oliveiro wrote:

In message [EMAIL PROTECTED], Tim Golden
wrote:


Alternatively, you might be able to commandline control
mencoder or ffmpeg itself to do this. Not sure, but there
must be *something* among those millions of command-line
options!


FFmpeg--yes!


Unfortunately it looks like I have the same problem as I do with pyglet 
- it's not support by my host.


It looks like I might have to process the files locally and then upload 
them. Painful.


Unless anyone else has any suggestions?

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


Re: Rewriting a bash script in python

2008-11-06 Thread Tim Rowe
2008/11/6 Lawrence D'Oliveiro [EMAIL PROTECTED]:

 Nothing wrong with rapid prototyping. :)

That's one requirements capture methodology, certainly. Actually,
there's quite a lot wrong with rapid prototyping, but there's quite a
lot wrong with all other requirements capture methodologies too, so
rapid prototyping is up there with the rest of them.


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


Re: Snippets management

2008-11-06 Thread Robert Lehmann
On Wed, 05 Nov 2008 19:55:51 -0600, Edwin wrote:

 Hi there,
 
 I've been looking for a snippet manager and found PySnippet but it
 requires PyGTK. Do you know any other option that doesn't need much?
[snip]

If you're looking for a snippet manager for actually *using* it (not 
educational purposes or something), I'd recommend your favorite editor 
and the version control system of your choice. I found DVCSes to be 
rather nice for local ad-hoc repositories (particulary Git_). If you'd 
like to modify your snippet system you could take a look at Mercurial or 
Bazaar, both being written in Python.

HTH,

.. _Git: http://git.or.cz/

-- 
Robert Stargaming Lehmann
--
http://mail.python.org/mailman/listinfo/python-list


Re: contextlib.nested()

2008-11-06 Thread Robert Lehmann
On Thu, 06 Nov 2008 01:02:34 -0800, brasse wrote:
 Hello!
 
 I have been running in to some problems when using contextlib.nested().
 My problem arises when using code similar to this:
 
 from __future__ import with_statement
 
 from contextlib import nested
 
 class Foo(object):
 
 def __init__(self, tag, fail=False):
 print 'ctor', tag
 self.tag = tag
 if fail:
 raise Exception()
 
 def __enter__(self):
 print '__enter__', self.tag
 return self
 
 def __exit__(self, *args):
 print '__exit__', self.tag
 
 with nested(Foo('a'), Foo('b', True)) as (a, b):
 print a.tag
 print b.tag
 
 Here the construction of b fails which in turn means that the
 contextmanager fails to be created leaving me a constructed object (a)
 that needs to be deconstructed in some way. I realize that nested() is
 in a tight spot here to do anything about it since it doesn't exist.
 This behavior makes it hard for me to use the with statement (using
 nested()) the way I want.
 
 Has anyone else been running in to this? Any tips on how to handle
 multiple resources?

Your problem does not seem to be connected to context managers. The error 
occurs before calling `contextlib.nested` at all::

foo = [Foo('a')]
   ctor a
with nested(*foo) as a: print a
   ... 
   __enter__ a
   [__main__.Foo object at 0x7fbc29408b90]
   __exit__ a
foo = [Foo('a'), Foo('b', True)]
   ctor a
   ctor b
   Traceback (most recent call last):
 File stdin, line 1, in module
 File stdin, line 7, in __init__
   raise Exception()
   Exception

If you need to deconstruct object `a` from your example, your staging is 
probably broken. Allocate the resource in `__init__` but only go live 
just in `__enter__`. If you do not enter the context, then, you won't 
need to deconstruct it as well.

HTH,

-- 
Robert Stargaming Lehmann
--
http://mail.python.org/mailman/listinfo/python-list


_checkversion.py

2008-11-06 Thread user
As part of the Python 2.5 distribution 
there are some Tools.  Are the notions 
behind checkversions.py still considered 
current?


I find that there is no _checkversion.py 
in my site-packages.


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


Re: Snippets management

2008-11-06 Thread Edwin
Robert Lehmann [EMAIL PROTECTED] writes:

 On Wed, 05 Nov 2008 19:55:51 -0600, Edwin wrote:

 Hi there,
 
 I've been looking for a snippet manager and found PySnippet but it
 requires PyGTK. Do you know any other option that doesn't need much?
 [snip]

 If you're looking for a snippet manager for actually *using* it (not 
 educational purposes or something), I'd recommend your favorite editor 
 and the version control system of your choice. I found DVCSes to be 
 rather nice for local ad-hoc repositories (particulary Git_). If you'd 
 like to modify your snippet system you could take a look at Mercurial or 
 Bazaar, both being written in Python.

 HTH,

 .. _Git: http://git.or.cz/

That sounds interesting. As I'm learning Python sometimes I look for
different approaches to the same problem so I use Git branches in order
to save every try. It's just that I'm looking for a 'global' place in my
system where I can save code ideas and useful snippets not particular to
any project. Quick access could be useful for some copy/paste
operations... I don't know. 

How would you set this up? A git folder 'snippets' maybe?

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


Re: How to re-import a function from a module?

2008-11-06 Thread Diez B. Roggisch
Kurda Yon wrote:

 Hi,
 
 I have the following small problem. I run Python interactively. In the
 beginning of the run I import many functions from many modules. Than I
 execute some commands and notice that one of the imported functions
 contains a mistake. I open another terminal in which I open the file
 with the problematic function and correct the function. However, the
 Python does not see my changes. It still uses the old version of the
 function. In principle I could close the Python session and reopen it
 again and import all functions agane. But it does not seem to be a
 convenient solution. Is there a way to force Python to re-import the
 function, i.e. to force it to use the new version of the function?

You can use reload, as Ben explained. Be aware though that this might
introduce subtle bugs. 

I personally prefer to write small test-scripts  simply execute them. If
you absolutely need to go interactive, you might consider using

python -i script.py

to drop to the prompt after the script has been executed.

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


Step-by-step exec

2008-11-06 Thread gregory . lielens
Hi,

I am using a small python file as an input file (defining constants,
parameters, input data, ...) for a python application.
The input file is simply read by an exec statement in a specific
dictionary, and then the application retrieve all the data it need
from the dictionary...
Everything is working nicely, but I'd like to have something a little
bit more robust regarding input file errors: now
any error in the python input script raise an exception and stop the
execution.
What I am trying to do is to execute it step-by-step, so that I can
capture the exception if one line (or multi-line statement) fails,
print a warning about the failure, and continue the execution fo the
following lines/statements. Of course, an error on one line can
trigger errors in the following lines, but it does not matter in the
application I have in mind, the goal is to parse as much of the input
script as possible, warn about the errors, and check what's inside the
dictionary after the exec.
One way to do it is to read the input script line per line, and exec
each line in turn. However, this is not convenient as it does not
allow multi-line statements, or basic control flow like if - else
statements or loops.

Is there a better way for a step-by-step exec? Syntax errors in the
input script are not really a problem (as it is generated elsewhere,
it is not directly edited by users), although it would be nice to
catch. The biggest problem are runtime errors (attribute error, value
error, ...). Maybe compiling the file into a code object, and
executing this code object step-by-step in a way similar to debug? pdb
module should do something similar

Best regards,

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


Re: Error loading modules

2008-11-06 Thread M.-A. Lemburg
The easiest way to debug such import problems is by telling
Python to be verbose:

python -vv -c import some_module

The generated output will then list all the locations where
Python looks for the module and is often handy to track
down reasons for Python not being able to load a module.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 06 2008)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extract frame from wmv

2008-11-06 Thread Martin

Tim Golden wrote:

Martin wrote:

Lawrence D'Oliveiro wrote:
In message [EMAIL PROTECTED], Tim 
Golden

wrote:


Alternatively, you might be able to commandline control
mencoder or ffmpeg itself to do this. Not sure, but there
must be *something* among those millions of command-line
options!


FFmpeg--yes!


Unfortunately it looks like I have the same problem as I do with 
pyglet - it's not support by my host.


It looks like I might have to process the files locally and then 
upload them. Painful.


Unless anyone else has any suggestions?



Well, since as far as I can see your host won't let you
install anything which isn't there already, you're down to
implementing a Python-only module to read a frame from a
.wmv. Which is, I would suggest, a not inconsiderable task.

Perhaps pre-filtering is the best solution after all.

TJG


Thanks Lawrence and Tim,

The irony is that I already have a Python only solution - it just 
requires 2.5!


I've actually worked out a way to extract and compress just the 
thumbnails from my local server and upload them without having to 
re-upload the video files (which took days) so I'm happy.


Thanks for the suggestions,

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


email for gpg encrypted?

2008-11-06 Thread Neal Becker
I know we have 'email' module.  Is there something I could use to produce 
properly mime-encoded gpg encrypted messages?

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


bind to HTMLayout or ubrowser

2008-11-06 Thread oyster
http://www.terrainformatica.com/htmlayout/ uses its own lightweight
HTML rendering engine, helps you to create applications with the Web
style user interface

http://ubrowser.com/ is a library that makes it a little easier to
embed the Mozilla Gecko rendering engine into your application

is there any python interface to it/them?

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


Re: Step-by-step exec

2008-11-06 Thread [EMAIL PROTECTED]
On Nov 6, 4:27 pm, [EMAIL PROTECTED] wrote:
 Hi,

 I am using a small python file as an input file (defining constants,
 parameters, input data, ...) for a python application.
 The input file is simply read by an exec statement in a specific
 dictionary, and then the application retrieve all the data it need
 from the dictionary...
 Everything is working nicely, but I'd like to have something a little
 bit more robust regarding input file errors: now
 any error in the python input script raise an exception and stop the
 execution.
 What I am trying to do is to execute it step-by-step, so that I can
 capture the exception if one line (or multi-line statement) fails,
 print a warning about the failure, and continue the execution fo the
 following lines/statements. Of course, an error on one line can
 trigger errors in the following lines, but it does not matter in the
 application I have in mind, the goal is to parse as much of the input
 script as possible, warn about the errors, and check what's inside the
 dictionary after the exec.
 One way to do it is to read the input script line per line, and exec
 each line in turn. However, this is not convenient as it does not
 allow multi-line statements, or basic control flow like if - else
 statements or loops.

Do you have control over the input file generation ? If the input file
can be easily divided into self sufficient blocks of code, you could
read each block in one at a time and do a compile() and exec(). Your
input file need not be a full python script too, you could just have
token delimited blocks of python code which are read in 1 block at a
time and then exec().

-srp


 Is there a better way for a step-by-step exec? Syntax errors in the
 input script are not really a problem (as it is generated elsewhere,
 it is not directly edited by users), although it would be nice to
 catch. The biggest problem are runtime errors (attribute error, value
 error, ...). Maybe compiling the file into a code object, and
 executing this code object step-by-step in a way similar to debug? pdb
 module should do something similar

 Best regards,

 Greg.

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


Re: Extract frame from wmv

2008-11-06 Thread Tim Golden

Martin wrote:

Lawrence D'Oliveiro wrote:
In message [EMAIL PROTECTED], Tim 
Golden

wrote:


Alternatively, you might be able to commandline control
mencoder or ffmpeg itself to do this. Not sure, but there
must be *something* among those millions of command-line
options!


FFmpeg--yes!


Unfortunately it looks like I have the same problem as I do with pyglet 
- it's not support by my host.


It looks like I might have to process the files locally and then upload 
them. Painful.


Unless anyone else has any suggestions?



Well, since as far as I can see your host won't let you
install anything which isn't there already, you're down to
implementing a Python-only module to read a frame from a
.wmv. Which is, I would suggest, a not inconsiderable task.

Perhaps pre-filtering is the best solution after all.

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


Re: bind to HTMLayout or ubrowser

2008-11-06 Thread Diez B. Roggisch
oyster wrote:

 http://www.terrainformatica.com/htmlayout/ uses its own lightweight
 HTML rendering engine, helps you to create applications with the Web
 style user interface
 
 http://ubrowser.com/ is a library that makes it a little easier to
 embed the Mozilla Gecko rendering engine into your application
 
 is there any python interface to it/them?

If you don't care about the engine itself, you might consider using PyQt4 +
the embedded webkit (Safari, chrome, konqueror) engine.

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


Re: Step-by-step exec

2008-11-06 Thread gregory . lielens
On Nov 6, 1:02 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 On Nov 6, 4:27 pm, [EMAIL PROTECTED] wrote:



  Hi,

  I am using a small python file as an input file (defining constants,
  parameters, input data, ...) for a python application.
  The input file is simply read by an exec statement in a specific
  dictionary, and then the application retrieve all the data it need
  from the dictionary...
  Everything is working nicely, but I'd like to have something a little
  bit more robust regarding input file errors: now
  any error in the python input script raise an exception and stop the
  execution.
  What I am trying to do is to execute it step-by-step, so that I can
  capture the exception if one line (or multi-line statement) fails,
  print a warning about the failure, and continue the execution fo the
  following lines/statements. Of course, an error on one line can
  trigger errors in the following lines, but it does not matter in the
  application I have in mind, the goal is to parse as much of the input
  script as possible, warn about the errors, and check what's inside the
  dictionary after the exec.
  One way to do it is to read the input script line per line, and exec
  each line in turn. However, this is not convenient as it does not
  allow multi-line statements, or basic control flow like if - else
  statements or loops.

 Do you have control over the input file generation ? If the input file
 can be easily divided into self sufficient blocks of code, you could
 read each block in one at a time and do a compile() and exec(). Your
 input file need not be a full python script too, you could just have
 token delimited blocks of python code which are read in 1 block at a
 time and then exec().

 -srp



  Is there a better way for a step-by-step exec? Syntax errors in the
  input script are not really a problem (as it is generated elsewhere,
  it is not directly edited by users), although it would be nice to
  catch. The biggest problem are runtime errors (attribute error, value
  error, ...). Maybe compiling the file into a code object, and
  executing this code object step-by-step in a way similar to debug? pdb
  module should do something similar

  Best regards,

  Greg.


Thanks for your input!
I had a similar solution in mind (with continuation comments to be
able to read multi-line statements, instead of statement delimiters,
but
I think your delimiter idea would be easier to implement).
The only problem is that files generated by current and older version
of the input generator (which do not have any kind of statement
delimiter)
will not be readable, or, if we just consider old file as one big
statement, will not offer the step-by-step execution. It would work
nice with new files,
but the best solution would be something that work also with older
auto-generated files...

In fact, the error in the input script are mainly caused by version
mismatch, and the step-by-step approach is
mainly for improving backward compatibility.
Having better backward compatibility starting from now on would be
nice, but having backward compatibility with previous versions would
be even better ;-)
contains multi-line statements
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering python sets

2008-11-06 Thread Mr . SpOOn
On Wed, Nov 5, 2008 at 10:03 PM, Arnaud Delobelle
[EMAIL PROTECTED] wrote:
 Only hashable objects can go in a set.  By default a class you define is
 not hashable (unless it descends from a hashable class).  To remedy this
 you can define a __hash__ method in your class.  IIRC the only
 requirement of a hash function is that two equal objects have the same
 hash.

Thanks, now it works.
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-11-06 Thread sturlamolden
On Nov 4, 6:51 pm, Paul Boddie [EMAIL PROTECTED] wrote:

 The language features look a lot like what others have already been
 offering for a while: keywords for parallelised constructs (clik_for)
 which are employed by solutions for various languages (C# and various C
 ++ libraries spring immediately to mind); spawning and synchronisation
 are typically supported in existing Python solutions, although
 obviously not using language keywords.

Yes, but there is not a 'concurrency platform' that takes care of
things like load balancing and testing for race conditions. If you
spawn with cilk++, the result is not that a new process or thread is
spawned. The task is put in a queue (scheduled using work stealing),
and executed by a pool of threads/processes.   Multiprocessing makes
it easy to write concurrent algorithms (as opposed to subprocess or
popen), but automatic load balancing is something it does not do. It
also does not identify and warn the programmer about race conditions.
It does not have a barrier synchronization paradigm, but it can be
constructed.

java.util.concurrent.forkjoin is actually based on cilk.

Something like cilk can easily be built on top of the multiprocessing
module. Extra keywords can and should be avoided. But it is easier in
Python than C. Keywords are used in cilk++ because they can be defined
out by the preprocessor, thus restoring the original seqential code.
In Python we can e.g. use a decorator instead.


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


Re: Snippets management

2008-11-06 Thread Robert Lehmann
On Thu, 06 Nov 2008 05:23:25 -0600, Edwin wrote:
[snip]
 As I'm learning Python sometimes I look for different approaches to the
 same problem so I use Git branches in order to save every try. It's
 just that I'm looking for a 'global' place in my system where I can
 save code ideas and useful snippets not particular to any project.
 Quick access could be useful for some copy/paste operations...
 I don't know.
 
 How would you set this up? A git folder 'snippets' maybe?
 
 Thanks for your ideas.

I don't think there is a one-size-fits-all solution.

Setting up a 'snippets' repository sounds good if you just want to be 
able to look back at what you've done and/or have a place to stash away 
quick tests. I have set up a 'sandbox' folder (unrevisioned) and put 
together a few shell aliases for easier access and it works pretty well. 
I almost never look back at that code though.

If you develop a lot of small scripts you think you'll reuse in your 
daily routine, you should add a dedicated 'bin' directory and add it to 
your PATH.

I've also seen people put together libraries of personal helpers, say, 
libedwin, but I don't think such mashups offer any particular semantic 
gain. They will just bloat over time and be vastly unused in most 
projects.

So, I don't really know what you should do. I'd go for a throw away 
location for quick tests; *real* libraries/programs where reasonable. If 
you need a particular algorithm and know you've used it in project XY, 
just go back to this project and copy it. No big deal. If it's a 
generally applicable algorithm, extracting a library might be a good idea 
then.

Just one last hint: Don't be overly shy in creating new Git repositories. 
They're pretty cheap and a shared history for *deeply unrelated projects* 
is seldom sensible (IMO). GitHub doesn't restrict you in your number of 
public repositories so that's no deal breaker either. :-)

Snippet'ly yours,

-- 
Robert Stargaming Lehmann
--
http://mail.python.org/mailman/listinfo/python-list


Re: contextlib.nested()

2008-11-06 Thread brasse
On Nov 6, 11:43 am, Robert Lehmann [EMAIL PROTECTED] wrote:
 On Thu, 06 Nov 2008 01:02:34 -0800, brasse wrote:
  Hello!

  I have been running in to some problems when using contextlib.nested().
  My problem arises when using code similar to this:

  from __future__ import with_statement

  from contextlib import nested

  class Foo(object):

      def __init__(self, tag, fail=False):
          print 'ctor', tag
          self.tag = tag
          if fail:
              raise Exception()

      def __enter__(self):
          print '__enter__', self.tag
          return self

      def __exit__(self, *args):
          print '__exit__', self.tag

  with nested(Foo('a'), Foo('b', True)) as (a, b):
      print a.tag
      print b.tag

  Here the construction of b fails which in turn means that the
  contextmanager fails to be created leaving me a constructed object (a)
  that needs to be deconstructed in some way. I realize that nested() is
  in a tight spot here to do anything about it since it doesn't exist.
  This behavior makes it hard for me to use the with statement (using
  nested()) the way I want.

  Has anyone else been running in to this? Any tips on how to handle
  multiple resources?

 Your problem does not seem to be connected to context managers. The error
 occurs before calling `contextlib.nested` at all::

     foo = [Foo('a')]
    ctor a
     with nested(*foo) as a: print a
    ...
    __enter__ a
    [__main__.Foo object at 0x7fbc29408b90]
    __exit__ a
     foo = [Foo('a'), Foo('b', True)]
    ctor a
    ctor b
    Traceback (most recent call last):
      File stdin, line 1, in module
      File stdin, line 7, in __init__
        raise Exception()
    Exception

 If you need to deconstruct object `a` from your example, your staging is
 probably broken. Allocate the resource in `__init__` but only go live
 just in `__enter__`. If you do not enter the context, then, you won't
 need to deconstruct it as well.

 HTH,

 --
 Robert Stargaming Lehmann

Diez, Robert,

OK. The practice of going live or doing non-trivial initialization
in __enter__ is new to me. I'm new to Python with a C++ background, so
that shouldn't be a surprise. :-)

Ideally I would like to put all initialization in __init__ since then
I would be able to use my object right after constructing it, without
having to use it in a with statement. The reason I'm struggling with
this is probably my C++ background. I'm rally accustomed to design
with RAII in mind. Acquiring all resources in the ctor and releasing
all resources in the dtor is *really* handy.

If you had a class that wanted to acquire some external resources that
must be released at some point, how would you rewrite the code from my
example?

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


Re: subprocess and PPID

2008-11-06 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Michele Petrazzo wrote:

 Lawrence D'Oliveiro wrote:

 See the prctl(2) man page.
 
 Just seen. It can be, bust since I cannot modify the child process and
 this syscall must be called from the child, I cannot use it.

You do the fork and then the exec, right? So do the prctl in-between.
--
http://mail.python.org/mailman/listinfo/python-list


Error importing wxPython

2008-11-06 Thread ron . reidy
Hi,

I just installed wxPython from http://wxpython.org/download.php.  When
I import (import wx), I get this error:

ImportError: DLL load failed: The application has failed to start
because its side-by-side configuration is incorrect. Please see the
application event log for more detail.

Has anyone had this problem and how can I resolve it?

Thanks in advance.

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


spam

2008-11-06 Thread skip
 I'm pretty sure all of the spam is automated, so your message won't
 get through to anyone.

D'Arcy Well, it got through to us adding to our spam problem.

Right.  I apologize that so much spam seems to be leaking through still.  I
am working on the problem.  I'm pretty sure at this point that I am seeing
all the spam (even those messages which gmail thoughtfully traps for me) and
have modified things slightly so that I can dig into the reasons why some
spams are missed and some pretty obvious hams are held.

So, best approach now when you see a spam message is: try to rein in your
sarcastic wit and just hit the 'd' key.

-- 
Skip Montanaro - [EMAIL PROTECTED] - http://www.webfast.com/~skip/
--
http://mail.python.org/mailman/listinfo/python-list


Python25\Tools\checkversions.py

2008-11-06 Thread Colin J. Williams

Is _checkversion.py used at all currently?

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


Re: 2.6, 3.0, and truly independent intepreters

2008-11-06 Thread sturlamolden
On Nov 5, 8:44 pm, Andy O'Meara [EMAIL PROTECTED] wrote:

 In a few earlier posts, I went into details what's meant there:

 http://groups.google.com/group/comp.lang.python/browse_thread/thread/...http://groups.google.com/group/comp.lang.python/msg/edae2840ab432344http://groups.google.com/group/comp.lang.python/msg/5be213c31519217b


All this says is:

1. The cost of serialization and deserialization is to large.
2. Complex data structures cannot be placed in shared memory.

The first claim is unsubstantiated. It depends on how much and what
you serialize. If you use something like NumPy arrays, the cost of
pickling is tiny. Erlang is a language specifically designed for
concurrent programming, yet it does not allow anything to be shared.

The second claim is plain wrong. You can put anything you want in
shared memory. The mapping address of the shared memory segment may
vary, but it can be dealt with (basically use integers instead of
pointers, and use the base address as offset.) Pyro is a Python
project that has investigated this. With Pyro you can put any Python
object in a shared memory region. You can also use NumPy record arrays
to put very complex data structures in shared memory.

What do you gain by placing multiple interpreters in the same process?
You will avoid the complication that the mapping address of the shared
memory region may be different. But this is a problem that has been
worked out and solved. Instead you get a lot of issues dealing with
DLL loading and unloading (Python extension objects).

The multiprocessing module has something called proxy objects, which
also deals with this issue. An object is hosed in a server process,
and client processes may access it through synchronized IPC calls.
Inside the client process the remote object looks like any other
Python object. The synchronized IPC is hidden away in an abstraction
layer. In Windows, you can also construct outproc ActiveX objects,
which are not that different from multiprocessing's proxy objects.

If you need to place a complex object in shared memory:

1. Check if a NumPy record array may suffice (dtypes may be nested).
It will if you don't have dynamically allocated pointers inside the
data structure.

2. Consider using multiprocessing's proxy objects or outproc ActiveX
objects.

3. Go to http://pyro.sourceforge.net, download the code and read the
documentation.

Saying that it can't be done is silly before you have tried.
Programmers are not that good at guessing where the bottlenecks
reside, even if we think we do.





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


Re: subprocess and PPID

2008-11-06 Thread [EMAIL PROTECTED]
On Nov 6, 3:09 pm, Lawrence D'Oliveiro [EMAIL PROTECTED]
central.gen.new_zealand wrote:
 In message [EMAIL PROTECTED], Michele Petrazzo wrote:

  Lawrence D'Oliveiro wrote:

  See the prctl(2) man page.

  Just seen. It can be, bust since I cannot modify the child process and
  this syscall must be called from the child, I cannot use it.

 You do the fork and then the exec, right? So do the prctl in-between.

You could also write a wrapper program that does a prctl and then
exec(actual command). Infact you could use a wrapper program to
portably poll for the parent if you dont want to prctl(); invoke this
wrapper from python, the wrapper can then invoke your actual command.

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


Re: contextlib.nested()

2008-11-06 Thread Diez B. Roggisch
brasse wrote:

 Hello!
 
 I have been running in to some problems when using
 contextlib.nested(). My problem arises when using code similar to
 this:
 
 from __future__ import with_statement
 
 from contextlib import nested
 
 class Foo(object):
 
 def __init__(self, tag, fail=False):
 print 'ctor', tag
 self.tag = tag
 if fail:
 raise Exception()
 
 def __enter__(self):
 print '__enter__', self.tag
 return self
 
 def __exit__(self, *args):
 print '__exit__', self.tag
 
 with nested(Foo('a'), Foo('b', True)) as (a, b):
 print a.tag
 print b.tag
 
 Here the construction of b fails which in turn means that the
 contextmanager fails to be created leaving me a constructed object (a)
 that needs to be deconstructed in some way. I realize that nested() is
 in a tight spot here to do anything about it since it doesn't exist.
 This behavior makes it hard for me to use the with statement (using
 nested()) the way I want.
 
 Has anyone else been running in to this? Any tips on how to handle
 multiple resources?

I don't fully understand this. Why is in need to be deconstructed? Sure, the
object is created, but whatever is actually done on initialization which is
non-trivial should of course to the __enter__-method - which isn't called.

So, a falls out of a scope  gets GC'ed. What else do you expect to happen?

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


SocketServer shutdown deadlock

2008-11-06 Thread Okko Willeboordse
All,

With Python 2.5 SocketServer features the shutdown method that can be
called from another thread to stop the serve_forever loop.

However;

When the shutdown method is called before serve_forever, shutdown will
never return.
This can happen when a server is stopped during startup.

In other words, the following program shouldn't hang but it does;

import SocketServer

server = SocketServer.ThreadingTCPServer((127.0.0.1, 12345),
SocketServer.BaseRequestHandler)
server.shutdown()

What to do?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to set a date field in a access databse

2008-11-06 Thread M.-A. Lemburg
On 2008-11-05 21:12, [EMAIL PROTECTED] wrote:
 Hi,
 I cannot get the following code to work
 
 import win32com.client
 import time
 
 engine = win32com.client.Dispatch(DAO.DBEngine.36)
 db=engine.OpenDatabase(rtestdate2.mdb)
 access = db.OpenRecordset(select * from test)
 
 access.AddNew()
 access.Fields(test).value=time.strptime('10:00AM', '%I:%M%p')
 access.Update()
 
 wherer test is a datetime field,
 How can I do this???

You could try to use mxODBC for this:

http://www.egenix.com/products/python/mxODBC/

Here's a very simple example for using mxODBC:

# On Windows:
from mx.ODBC import Windows as Database

# On Mac OS X:
from mx.ODBC import iODBC as Database

# On Linux/BSD/etc.:
from mx.ODBC import unixODBC as Database
# or
from mx.ODBC import iODBC as Database

# Open a connection to the database
connection = Database.DriverConnect('DSN=datasourcename;'
'UID=username;'
'PWD=password;'
'KEYWORD=value')
# replace the values accordingly, add new keyword-value pairs as
# necessary for your data source; data sources are configured
# in the ODBC manager

# Create a cursor; this is used to execute commands
cursor = connection.cursor()

# Create a table
cursor.execute('CREATE TABLE mxodbcexample1 '
   ' (id integer, name varchar(10), data varchar(254))')
# this command does not create a result set, so there's nothing
# to fetch from the database; however in order to make the
# change permanent, we need to commit the change
connection.commit()

# Prepare some data rows to add to the table, ie. a list of tuples
rows = []
for i in range(42):
name = 'name-%i' % i
data = 'value-%i' % i
rows.append((i, name, data))

# Add the data in one go; the values from the tuples get assigned
# to the ?-mark parameter markers in the SQL statement based on
# their position and the SQL statement is executed once for
# each tuple in the list of rows
cursor.executemany('INSERT INTO mxodbcexample1 VALUES (?,?,?)',
   rows)

# If you apply changes to the database, be sure to commit or
# rollback your changes; a call to .commit() or .rollback()
# will implicitly start a new transaction
connection.commit()

# Now fetch some data rows
from_id = 40
to_id = 42
cursor.execute('SELECT * FROM mxodbcexample1'
   ' WHERE (id = ?) and (id  ?)',
   (from_id, to_id))

# Fetch the results
for i, row in enumerate(cursor.fetchall()):
print 'Row %i: %r' % (i, row)

# Remove the table again
cursor.execute('DROP TABLE mxodbcexample1')
connection.commit()

# Close the connection
connection.close()


With MS Access this gives:

Row 0: (40, 'name-40', 'value-40')
Row 1: (41, 'name-41', 'value-41')

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 06 2008)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


I need a simple windows form handle.

2008-11-06 Thread 一首诗
Hi all,

Today I was writing a simple test app for a video decoder library.

I use python to parse video files and input data to the library.

I got a problem here,  I need a windows form, and send the form handle
to the library as a parameter, then it can output video on the form.

Here is my problem:

  What is the simplest way to get a windows form which has a handle?

I tried to use win32py but it seems to be to complicate for my
purpose.
And the form would block the main thread even if I call its DoModal
method on another thread.

=

PS: Finally I decided I can not finish it today so I write a WinForm
App in C# in 5 minutes and send video from my python app to it by UDP.

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


Re: Plz help..SocketServer UDP server losing lots of packets

2008-11-06 Thread I D
Hello James,
Thanks for your response.
But I cannot use a third party software, I need to use the exisiting API's
within python.
As I am new to python, I suspected that I should go by a simpler approach
and so
scrapped off the below code and wrote a very simple UDP server code as
follows:

logFileName = '/home/msat/gsc/logs/' + compNum + '/logparsertracedump.log'
logfile = open(logFileName, w)
from socket import *
host = 121.3.0.1
port = PORT
buf = 4096
addr = (host,port)
# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.setsockopt(SOL_SOCKET, SO_RCVBUF, 8388608)
UDPSock.bind(addr)
while 1:
data,addr = UDPSock.recvfrom(buf)
if not fileExists(logFileName):
logfile = open(logFileName, a)
logfile.writelines(data)
# Close socket
UDPSock.close()

Even this seems to lose packets, I would really appreciate if any pointers
can be provided to improve my code.

Thanks,
Sam

On Wed, Nov 5, 2008 at 7:46 PM, James Mills [EMAIL PROTECTED]wrote:

 On Thu, Nov 6, 2008 at 9:53 AM,  [EMAIL PROTECTED] wrote:
  logFileName = 'log.txt'
 logfile = open(logFileName, a)
 class MyUDPServer(SocketServer.UDPServer):
 def server_bind(self):
 self.socket.setsockopt(socket.SOL_SOCKET,
  socket.SO_RCVBUF, 8388608)
 self.socket.bind(self.server_address)
 
 class LogsDumpHandler(SocketServer.DatagramRequestHandler):
 def handle(self):
 global logfile
  # fileExists is a function which checks the existence of a file
 if not fileExists(logFileName):
 logfile = open(logFileName, a)
 logfile.writelines(self.rfile.readlines())
 
 server = MyUDPServer((,PORT), LogsDumpHandler)
 server.serve_forever()
 logfile.close()

 This is horrible code :/

 Try these instead:
  * UDPServer -
 http://trac.softcircuit.com.au/circuits/browser/examples/udpserver.py
  * UDPClient  -
 http://trac.softcircuit.com.au/circuits/browser/examples/udpclient.py

 Example usage
 --

 ~/circuits/examples
 $ ./udpserver.py
 127.0.0.1, 9000:
 test
 127.0.0.1, 9000:
 hi

 ~/circuits/examples
 $ ./udpclient.py -b 127.0.0.1:9000 127.0.0.1:8000
 test
 127.0.0.1, 8000:
 test
 hi
 127.0.0.1, 8000:
 hi

 You can download circuits from http://trac.softcircuit.com.au/circuits/
 or get the latest development version by using Mercurial (1):
 hg clone http://hg.softcircuit.com.au/projects/circuits/

 cheers
 James

 [1] http://www.selenic.com/mercurial/wiki/

 --
 --
 -- Problems are solved by method

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


CGI Python problem

2008-11-06 Thread [EMAIL PROTECTED]
Hi all,

I'm trying to get python to work with cgi for a small intranet site,
however even a simply hello world test isn't working. Here is the
test file:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb; cgitb.enable()

print Content-Type: text/plain;charset=utf-8
print

print Hello World!

I've placed this file in both public_html and as a test in public_html/
cgi-bin directories in my local user account (I dont have root access
- its a corparate network). The file definitely has read and execute
permission (744) as have the assoicated directories. However when I
navigate to the file with my browser I get a 500 page?! The code was
written fully in linux, so its not some odd windows/linux line
termination issue.

As a test I tried a perl cgi hello world test, and this worked
correctly. The apache server appears to be locked down tightly, as
allowOverwrite is None, so I can't do anything in .htaccess files.

Any thoughts on how I might debug this or where the problem is
--
http://mail.python.org/mailman/listinfo/python-list


Re: Plz help..SocketServer UDP server losing lots of packets

2008-11-06 Thread James Mills
On Fri, Nov 7, 2008 at 12:57 AM, I D [EMAIL PROTECTED] wrote:
 Thanks for your response.
 But I cannot use a third party software, I need to use the exisiting API's
 within python.

Why ?

 Even this seems to lose packets, I would really appreciate if any pointers
 can be provided to improve my code.

You do realize that UDP is the User Datagram
Protocol and has no Control mechanisms.
You _cannot_ guarantee that packets will
arrive in the right order, if at all.

In all my tests however on local machines
and across machines in a LAN, I don't
loose packets. I do recommend you use
circuits (or twisted).

--JamesMills

-- 
--
-- Problems are solved by method
--
http://mail.python.org/mailman/listinfo/python-list


Re: Plz help..SocketServer UDP server losing lots of packets

2008-11-06 Thread I D
On Thu, Nov 6, 2008 at 10:27 AM, James Mills
[EMAIL PROTECTED]wrote:

 On Fri, Nov 7, 2008 at 12:57 AM, I D [EMAIL PROTECTED] wrote:
  Thanks for your response.
  But I cannot use a third party software, I need to use the exisiting
 API's
  within python.

 Why ?


@Sam@ That is the requirement of the assignment.




  Even this seems to lose packets, I would really appreciate if any
 pointers
  can be provided to improve my code.

 You do realize that UDP is the User Datagram
 Protocol and has no Control mechanisms.
 You _cannot_ guarantee that packets will
 arrive in the right order, if at all.


@Sam@ I understand that, but a similar UDP server written in C works
perfect, not even a single packet loss, that leads me to believe that I am
not doing something right in my python code.



 In all my tests however on local machines
 and across machines in a LAN, I don't
 loose packets. I do recommend you use
 circuits (or twisted).

 --JamesMills

 --
  --
 -- Problems are solved by method

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


Re: Plz help..SocketServer UDP server losing lots of packets

2008-11-06 Thread Ben Sizer
On Nov 6, 12:46 am, James Mills [EMAIL PROTECTED]
wrote:

 Try these instead:
  * UDPServer 
 -http://trac.softcircuit.com.au/circuits/browser/examples/udpserver.py
  * UDPClient  
 -http://trac.softcircuit.com.au/circuits/browser/examples/udpclient.py

Since there's no contact details on the Circuits site, and the guest
Trac account doesn't work (it asks the admin to verify the email),
then I'll post here: it appears that the Hello World example is wrong,
trying to add an instance of a 'hello' object that doesn't exist. I've
not tried to run the example, but it certainly confused me when trying
to work out how Circuits works.

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


More __init__ methods

2008-11-06 Thread Mr . SpOOn
Hi,
I know there can be only one __init__ method (at least, I think).

Often I need an object to be created in different ways, for example
passing a string as argument, or an integer, or another object. To
achieve this I put the default value of the arguments to None and then
I some if...elif inside the __init__.

Is this a good practice? It actually works, but sometimes I think that
in this way the __init__ method can become too complicated, for
example when an object can be created using more than one argument and
in different combinations.

Hope my doubt is clear.
--
http://mail.python.org/mailman/listinfo/python-list


Re: More __init__ methods

2008-11-06 Thread Tim Golden

Mr.SpOOn wrote:

Hi,
I know there can be only one __init__ method (at least, I think).

Often I need an object to be created in different ways, for example
passing a string as argument, or an integer, or another object. To
achieve this I put the default value of the arguments to None and then
I some if...elif inside the __init__.

Is this a good practice? It actually works, but sometimes I think that
in this way the __init__ method can become too complicated, for
example when an object can be created using more than one argument and
in different combinations.


My own approach -- and I don't think I'm unique in this -- is
to use class methods called things like from_string or from_date,
possibly with a convenience function which tries to guess from a
passed-in parameter which of them is to be used.

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


Re: Error importing wxPython

2008-11-06 Thread Mike Driscoll
On Nov 6, 8:09 am, [EMAIL PROTECTED] wrote:
 Hi,

 I just installed wxPython fromhttp://wxpython.org/download.php.  When
 I import (import wx), I get this error:

 ImportError: DLL load failed: The application has failed to start
 because its side-by-side configuration is incorrect. Please see the
 application event log for more detail.

 Has anyone had this problem and how can I resolve it?

 Thanks in advance.

 --
 Ron Reidy


I haven't seen that one before. What OS are you using? Did you install
the latest wxPython? Is there a previous version of wxPython already
installed? If so, was that intentional?

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


Re: More __init__ methods

2008-11-06 Thread Marc 'BlackJack' Rintsch
On Thu, 06 Nov 2008 16:49:08 +0100, Mr.SpOOn wrote:

 I know there can be only one __init__ method (at least, I think).
 
 Often I need an object to be created in different ways, for example
 passing a string as argument, or an integer, or another object. To
 achieve this I put the default value of the arguments to None and then I
 some if...elif inside the __init__.
 
 Is this a good practice? It actually works, but sometimes I think that
 in this way the __init__ method can become too complicated, for example
 when an object can be created using more than one argument and in
 different combinations.

I'm usually using `classmethod()`\s as alternative constructors then. 
For example:

class A(object):
def __init__(self, a, b, c):
self.a = a
# ...

@classmethod
def from_string(cls, s):
# ...
return cls(a, b, c)

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error importing wxPython

2008-11-06 Thread Chris Mellon
On Thu, Nov 6, 2008 at 8:09 AM,  [EMAIL PROTECTED] wrote:
 Hi,

 I just installed wxPython from http://wxpython.org/download.php.  When
 I import (import wx), I get this error:

 ImportError: DLL load failed: The application has failed to start
 because its side-by-side configuration is incorrect. Please see the
 application event log for more detail.

 Has anyone had this problem and how can I resolve it?

 Thanks in advance.


downloading and installing this package should fix the problem:

http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BFdisplaylang=en
--
http://mail.python.org/mailman/listinfo/python-list


Re: CGI Python problem

2008-11-06 Thread Tim Chase

I've placed this file in both public_html and as a test in public_html/
cgi-bin directories in my local user account (I dont have root access
- its a corparate network). The file definitely has read and execute
permission (744) as have the assoicated directories.


My guess would be the permissions are awry -- if I parse that 
correctly, 744 is -rwxr--r-- which means that other users (such 
as the user your server runs as, likely www or wwwdata?) 
can't execute the shell-script.  As a first pass, I'd ensure that 
the file has permissions, and the directory can be scanned by the 
webserver (eXecute permissions on the containing directory):


  bash$ cd ~/public_html/cgi-bin
  bash$ chmod go+rx test.py .


As a test I tried a perl cgi hello world test, and this worked
correctly.


If the perl script is working correctly, I suspect the directory 
permissions are set correctly, so I'd compare permission of the 
.pl vs. the .py scripts to see if they're the same. 
Alternatively, if your server is running mod_perl, it might be 
short circuiting the CGI aspect, detecting the .pl file  running 
it, and thus might be a red herring.  (not using perl/mod_perl, I 
don't know the ins and outs of this, so I could be way off 
base on this line of thinking)


Just my first-pass debugging thoughts,

-tkc








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


Re: Python 2.3.7 Does not compile on Ubuntu 8.10 i386

2008-11-06 Thread zenzike
I came across this today, and found a similar bug in launchpad [1].
The following commands worked for me (including cleaning up
beforehand):

cd Python-2.3.7
make distclean
./configure BASECFLAGS=-U_FORTIFY_SOURCE
make

I hope that helps.

zenzike

[1] https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/286334
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6, GUI not working on vista?

2008-11-06 Thread alphadog
On Oct 5, 4:13 am, Lawrence D'Oliveiro [EMAIL PROTECTED]
central.gen.new_zealand wrote:
 In message [EMAIL PROTECTED], Michel Claveau - NoSpam

 SVP ; merci wrote:
  Another way is to de-activate UAC.

 Please don't be stupid!

How about a compromise: Disable UAC. Install Python for all. Re-
enable UAC. Why do people have to be so black-and-white?
--
http://mail.python.org/mailman/listinfo/python-list


Re: CGI Python problem

2008-11-06 Thread Tim O'Toole
Thanks for replying Tim,

Here is the permissions, which I think are definitely right now:

drwxrwxrwx   8   4.0K Nov  6 13:34 public_html/

drwxrwxrwx   2   4.0K Nov  6 13:35 cgi-bin/ [inside public_html]

-rw-r-xr-x  1    117 Nov  6 11:39 test_pl.cgi* [inside cgi-bin]
-rw-r-xr-x  1    168 Nov  6 13:35 test_py.cgi* [inside cgi-bin]

note both have *.cgi extensions otherwise plain text is shown.


the perl file correctly outputs hello world whereas the python file
gives a 500 internal server error warning.

Also I think I should be getting a traceback since I used import
cgitb; cgitb.enable() I wonder does this suggest the python
interpreter hasn't be found?


Also I'm not sure how to check if the server is running mod_perl?


Thanks for the help, much appreciated


 My guess would be the permissions are awry -- if I parse that correctly, 744
 is -rwxr--r-- which means that other users (such as the user your server
 runs as, likely www or wwwdata?) can't execute the shell-script.  As a
 first pass, I'd ensure that the file has permissions, and the directory can
 be scanned by the webserver (eXecute permissions on the containing
 directory):

  bash$ cd ~/public_html/cgi-bin
  bash$ chmod go+rx test.py .

 As a test I tried a perl cgi hello world test, and this worked
 correctly.

 If the perl script is working correctly, I suspect the directory permissions
 are set correctly, so I'd compare permission of the .pl vs. the .py scripts
 to see if they're the same. Alternatively, if your server is running
 mod_perl, it might be short circuiting the CGI aspect, detecting the .pl
 file  running it, and thus might be a red herring.  (not using
 perl/mod_perl, I don't know the ins and outs of this, so I could be way
 off base on this line of thinking)

 Just my first-pass debugging thoughts,

 -tkc









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


Re: Printing with interspersed element

2008-11-06 Thread Kirk Strauser
At 2008-10-30T21:10:09Z, Paulo J. Matos [EMAIL PROTECTED] writes:

 Thanks for the tip but that has an issue when dealing with potentially
 millions of objects. You are creating a string in memory to then dump
 to a file [or screen] while you could dump to the file [or screen] as
 you go through the original string. Right?

How about:

def alternator(lst, sep):
for index, item in enumerate(lst):
if index:
yield sep
yield item

for item in alternator(list_of_objects, 10):
print item,

-- 
Kirk Strauser
The Day Companies
--
http://mail.python.org/mailman/listinfo/python-list


Re: contextlib.nested()

2008-11-06 Thread Diez B. Roggisch
 Diez, Robert,
 
 OK. The practice of going live or doing non-trivial initialization
 in __enter__ is new to me. I'm new to Python with a C++ background, so
 that shouldn't be a surprise. :-)
 
 Ideally I would like to put all initialization in __init__ since then
 I would be able to use my object right after constructing it, without
 having to use it in a with statement. The reason I'm struggling with
 this is probably my C++ background. I'm rally accustomed to design
 with RAII in mind. Acquiring all resources in the ctor and releasing
 all resources in the dtor is *really* handy.

Yes, but this is a C++ idiom that does not translate well to python's
GC-based approach. Which is the *exact* reason why contexts have been
created in the first place.

 If you had a class that wanted to acquire some external resources that
 must be released at some point, how would you rewrite the code from my
 example?

If you *can*, use a context. Use __enter__ and __exit__. Try really hard to
use it that way.

If not - create a specific finalize-method or some such, and try not to
forget to call that. Potentially with an atexit-handler or some such.

the problem is that python can't guarantee that a __del__-method is invoked
at all, and *if* it is, it might find other stuff being released already
that it relies upon - e.g. imported modules being freed  not known
anymore.

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


Problem with shelve

2008-11-06 Thread bluesmanu
Hi all,

I am trying to use the shelve module to save an object of a 'Electron'
class I made into a file. The writing goes well but the reading goes :

 e=f['0']
Traceback (most recent call last):
  File stdin, line 1, in module
  File shelve.py, line 113, in __getitem__
value = Unpickler(f).load()
AttributeError: 'module' object has no attribute 'Electron'

any idea of what I am doing wrong?

Thanks!
ET
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-11-06 Thread Joe Strout

On Nov 5, 2008, at 12:29 AM, Dennis Lee Bieber wrote:


C++:
void foo(PersonPtr who) {
who-zipcode = 12345;
}


Please show us the type definition of PersonPtr


Sorry, that'd be obvious to anyone experienced in C++, but I shouldn't  
assume.  It would be:


typedef Person* PersonPtr;

It's a pretty standard idiom, precisely because it is so much more  
common to need a variable of the pointer type than of the class type  
itself.



Java:
void foo(Person who) {
who.zipcode = 12345;
}


Please show us the type definition of Person


No.  It's a class, and you can see that it defines a zipcode member;  
nothing more is needed for the sake of this example.  (The Java  
designers realized that needing object reference variables is so  
overwhelmingly more common than needing non-pointer variables, that  
they eliminated the pointer syntax and made every variable of object  
type actually a pointer to the object data, just as in RB, .NET, and  
Python.)



REALbasic/VB.Net:
Sub foo(ByVal who as Person)
who.zipcode = 12345
End Sub


Note they YOU, as the programmer, explicitly told the language to
use a call-by-value


Correct; these languages support both call-by-value and call-by- 
reference.  ByVal is the default, but you can still specify it (as  
I've done here) if you want to be explicit.



-- and you still have not shown us the definition of Person


Right, again, there is nothing you need to know about it not already  
evident from the example.



Python:
def foo(who):
who.zipcode = 12345


Note that there is NO PROGRAMMER CONTROL over the passing mechanism.


Quite right.  (Same too in Java.)  Some languages offer both call-by- 
value and call-by-reference; but Java and Python offer only call-by- 
value.



5. You see that the first three languages above are passing a
reference by value and using that to mutate and object, yet for
reasons still mysterious, the Python example (which has exactly the
same behavior) must be doing something different.


I do not... I see the programmer telling the language that a
reference is to be taken of some object and that this reference is
/then/ to be passed.


Quite right (and that's what I said).  The reference is being passed.   
By value.  And then that reference is used to mutate an object.


AND the programmer is also (C++) explicitly dereferencing (by use of  
-)!


Yep, - is the dereference operator in C++; in Java, RB, .NET, and  
Python, it's ..  Different characters, same meaning.



The syntax, in C/C++ is different for
accessing the parameter by value vs by reference (pointer -- C++ is
smarter in that it allows declaring the parameter as a ref and the
language automatically takes the address on the caller's side, and
dereferences on the called side -- but that notation is STILL a
programmer responsibility).


Careful here -- a ref parameter really is passed by reference; that's  
not the same as passing a pointer by value, which is what's shown  
above.  It's the C++ equivalent of the ByRef keyword in RB/VB.NET.


Java passes /objects/ by reference, but passes native types (base  
numerics) by value


No, it passes everything by value.  who in the Java example is not  
an object; it is an object reference.  It was passed by value.  If it  
were passed by reference, you'd be able to make a swap function that  
exchanges the objects referred to by two variables, but you can't.   
This is explained more fully here:


  http://javadude.com/articles/passbyvalue.htm

-- can you create a Java example where you pass a base numeric by  
reference?


No, because Java (like Python) has only call-by-value.


By your argument, even FORTRAN is call-by-value.


No, FORTRAN's an oddball: it passes everything by reference.

You obfuscate the mechanics used at the machine language level with  
the semantics of the

language itself.


No, I haven't said anything at all about what's happening at the  
machine language level, and I frankly don't care.  This is about how  
the language behaves.



FORTRAN is the language commonly used to explain call-by-reference!


Quite right.  So, please try to convert any of those FORTRAN  
explanations into Python or Java.  Can't be done.  In C++ or RB/ 
VB.NET, it can be done only by using the special by-reference syntax  
( or ByRef).


I'm not sure where you got the idea that I thought FORTRAN is call-by- 
value.  I never said or implied any such thing.  And the examples  
above aren't meant to prove that those languages are using by-value;  
they're meant to show that mutating an object via a reference passed  
in proves NOTHING about how that reference was passed.  This is to  
invalidate the argument (frequently heard around here) that Python  
must use call-by-reference since you can mutate an object passed to a  
function.


As should be painfully clear by now, that argument is total bunk.  You  
can pass an object reference by value, and use it to 

Re: Finding the instance reference of an object

2008-11-06 Thread Joe Strout

On Nov 4, 2008, at 12:57 PM, Hendrik van Rooyen wrote:


4. You now see how a mutating an object within a function tells you
NOTHING about how the reference to that object was passed.



5. You see that the first three languages above are passing a
reference by value and using that to mutate and object, yet for
reasons still mysterious, the Python example (which has exactly the
same behavior) must be doing something different.


This is dialectic nit picking - WTF makes passing a reference by  
value
different from passing a reference - the salient point is that its  
a reference

that is passed


I know it seems nit-picky on the surface, but it is important.  It is  
the distinction that lets you answer whether:


def foo(x):
   x = Foo()

x = Bar()
foo(x)

...results in x (after the call) now referring to a Foo, or still  
referring to a Bar.


If x is a reference passed by value, then the assignment within the  
foo method can't affect the x that was passed in.  But if it is passed  
by reference, then it does.  (Also, if it is passed by reference, then  
you probably wouldn't be able to pass in a literal or computed value,  
but only a simple variable.)



- would you expect another level of indirection - a reference to
the reference, or what, before you admit that the thing that is  
passed is a

reference and not a copied value of the OBJECT that is of interest.


Um, no, I've admitted that it's a reference all along.  Indeed, that's  
pretty much the whole point: that variables in Python don't contain  
objects, but merely contain references to objects that are actually  
stored somewhere else (i.e. on the heap).  This is explicitly stated  
in the Python docs [1], yet many here seem to want to deny it.


Looks to me that even if there were ten levels of indirection you  
would still
insist that its a pass by value because in the end, its the actual  
memory

address of the first pointer in the queue that is passed.


No, it's entirely possible for an OOP language to have pass by  
reference, and, to put it your way, this adds one more level of  
indirection.  Look at the C++ and RB/VB.NET examples at [2].  But  
Python and Java do not offer this option.


If that is what you mean, it is obviously trivially true - but then  
ALL
calling can only be described as call by value - which makes  
nonsense

of what the CS people have been doing all these years.


That would indeed be nonsense.  But it's also not what I'm saying.   
See [2] again for a detailed discussion and examples.  Call-by-value  
and call-by-reference are quite distinct.



Calling by value is not a useful definition of Pythons behaviour.


It really is, though.  You have to know how the formal parameter  
relates to the actual parameter.  Is it a copy of it, or an alias of  
it?  Without knowing that, you don't know what assignments to the  
formal parameter will do, or even what sort of arguments are valid.   
Answer: it's a copy of it.  Assignments don't affect the actual  
parameter at all.  This is exactly what call by value means.


Best,
- Joe

[1] http://www.python.org/doc/2.5.2/ext/refcounts.html
[2] http://www.strout.net/info/coding/valref/

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


Weird behavior with lexical scope

2008-11-06 Thread mrstevegross
I ran into a weird behavior with lexical scope in Python. I'm hoping
someone on this forum can explain it to me.

Here's the situation: I have an Outer class. In the Outer class, I
define a nested class 'Inner' with a simple constructor. Outer's
constructor creates an instance of Inner. The code looks like this:

=
class Outer:
  class Inner:
def __init__(self):
  pass
  def __init__ (self):
a = Inner()
Outer()
=

However, the above code doesn't work. The creation of Inner() fails.
The error message looks like this:

  File /tmp/foo.py, line 12, in module
Outer()
  File /tmp/foo.py, line 10, in __init__
a = Inner()
NameError: global name 'Inner' is not defined

This surprises me! Since the construction of Inner takes place within
the lexical scope 'Outer', I assumed the interpreter would search the
Outer scope and find the 'Inner' symbol. But it doesn't! If I change:
  a = Inner()
to
  a = Outer.Inner()

it works fine, though.

So, can anyone explain to me how Python looks up symbols? It doesn't
seem to be searching the scopes I expected...

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


Re: Python 2.6, GUI not working on vista?

2008-11-06 Thread Steve Holden
alphadog wrote:
 On Oct 5, 4:13 am, Lawrence D'Oliveiro [EMAIL PROTECTED]
 central.gen.new_zealand wrote:
 In message [EMAIL PROTECTED], Michel Claveau - NoSpam

 SVP ; merci wrote:
 Another way is to de-activate UAC.
 Please don't be stupid!
 
 How about a compromise: Disable UAC. Install Python for all. Re-
 enable UAC. Why do people have to be so black-and-white?

Because they insist on believing each question has exactly one correct
answer.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: spam

2008-11-06 Thread D'Arcy J.M. Cain
On Thu, 6 Nov 2008 07:32:26 -0600
[EMAIL PROTECTED] wrote:
  I'm pretty sure all of the spam is automated, so your message won't
  get through to anyone.
 
 D'Arcy Well, it got through to us adding to our spam problem.
 
 Right.  I apologize that so much spam seems to be leaking through still.  I

In fact my system successfully filtered out the original spam so that
was not my problem.

 am working on the problem.  I'm pretty sure at this point that I am seeing
 all the spam (even those messages which gmail thoughtfully traps for me) and
 have modified things slightly so that I can dig into the reasons why some
 spams are missed and some pretty obvious hams are held.

I am sure that we all appreciate your efforts.  That doesn't mean that
we should depend on you to block 100% of the spam.  We need to take
some responsibility on our own systems too.

 So, best approach now when you see a spam message is: try to rein in your
 sarcastic wit and just hit the 'd' key.

Well, yes, that was my point.  I had managed to filter out the spam but
then had to deal with someone responding here to a spam that I never
saw.  The sarcasm was directed at the person who replied to the spam
rather than hitting the 'd' key.

This conversation sounds like we are in violent agreement.  :-)

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-11-06 Thread Walter Overby
Hi,

I've been following this discussion, and although I'm not nearly the
Python expert that others on this thread are, I think I understand
Andy's point of view.  His premises seem to include at least:

1. His Python code does not control the creation of the threads.  That
is done at the app level.
2. Perhaps more importantly, his Python code does not control the
allocation of the data he needs to operate on.  He's got, for example,
an opaque OS object that is manipulated by CPU-intensive OS
functions.

sturlamolden suggests a few approaches:

 1. Check if a NumPy record array may suffice (dtypes may be nested).
 It will if you don't have dynamically allocated pointers inside the
 data structure.

I suspect that the OS is very likely to have dynamically allocated
pointers inside their opaque structures.

 2. Consider using multiprocessing's proxy objects or outproc ActiveX
 objects.

I don't understand how this would help.  If these large data
structures reside only in one remote process, then the overhead of
proxying the data into another process for manipulation requires too
much IPC, or at least so Andy stipulates.

 3. Go to http://pyro.sourceforge.net, download the code and read the
 documentation.

I don't see how this solves the problem with 2.  I admit I have only
cursory knowledge, but I understand remoting approaches to have the
same weakness.

I understand Andy's problem to be that he needs to operate on a large
amount of in-process data from several threads, and each thread mixes
CPU-intensive C functions with callbacks to Python utility functions.
He contends that, even though he releases the GIL in the CPU-bound C
functions, the reacquisition of the GIL for the utility functions
causes unacceptable contention slowdowns in the current implementation
of CPython.

After reading Martin's posts, I think I also understand his point of
view.  Is the time spent in these Python callbacks so large compared
to the C functions that you really have to wait?  If so, then Andy has
crossed over into writing performance-critical code in Python.  Andy
proposes that the Python community could work on making that possible,
but Martin cautions that it may be very hard to do so.

If I understand them correctly, none of these concerns are silly.

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


Re: Weird behavior with lexical scope

2008-11-06 Thread Arnaud Delobelle
mrstevegross [EMAIL PROTECTED] writes:

 I ran into a weird behavior with lexical scope in Python. I'm hoping
 someone on this forum can explain it to me.

 Here's the situation: I have an Outer class. In the Outer class, I
 define a nested class 'Inner' with a simple constructor. Outer's
 constructor creates an instance of Inner. The code looks like this:

 =
 class Outer:
   class Inner:
 def __init__(self):
   pass
   def __init__ (self):
 a = Inner()
 Outer()
 =

 However, the above code doesn't work. The creation of Inner() fails.

This is because there isn't lexical scoping in class scopes.

Try replacing

a = Inner()

with

a = Outer.Inner()


Alternatively,

class Outer:
class Inner:
...
def __init__(self, Inner=Inner):
a = Inner()

HTH

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


Re: Weird behavior with lexical scope

2008-11-06 Thread mrstevegross
 def __init__(self, Inner=Inner):

Ok, the Inner=Inner trick works. What the heck does that do, anyway?
I've never seen that formulation.

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


python bug when subclassing list?

2008-11-06 Thread Hamish McKenzie
I want to write a Vector class and it makes the most sense to just subclass 
list.  I also want to be able to instantiate a vector using either:

Vector( 1, 2, 3 )
OR
Vector( [1, 2, 3] )


so I have this:

class Vector(list):
def __new__( cls, *a ):
try:
print a
return list.__new__(cls, a)
except:
print 'broken'
return list.__new__(cls, list(a))


doing Vector( 1, 2, 3 ) on this class results in a TypeError - which doesn't 
seem to get caught by the try block (ie broken never gets printed, and it 
never tries to

I can do pretty much the exact same code but inheriting from tuple instead of 
list and it works fine.

is this a python bug?  or am I doing something wrong?

thanks,
-h.
--
http://mail.python.org/mailman/listinfo/python-list


Looking for a nitty-gritty Python Ajax middleware script to fire off a number of processors

2008-11-06 Thread David Shi
Dear All,
 
I am looking for a nitty-gritty Python Ajax script to fire off a number of 
processing programmes, periodically checking their operations, sending messages 
back to an HTML div form by sending back the links of generated data files, to 
be downloaded by end users.
 
I am using .NET IIS 6.0 and Windows Server.
 
Regards.
 
David


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


Spring Python 0.8.0 has been released/Spring Python goes green

2008-11-06 Thread Goldfish
Spring Python, the python version of the Spring Framework, has just
released version 0.8.0. This release contains a refactored IoC
container supporting four formats (XMLConfig, PythonConfig/@Object,
PyContainerConfig, and SpringJavaConfig); replacement of the term
component with object in all APIs, classnames, etc.; and other bug
fixes and API cleanup.

This release also includes a new, spring-green web page you can see at
http://springpython.webfactional.com.

A key requirement to using this version of Spring Python is
installation of Amara XML parsing libraries (https://
fisheye.springframework.org/browse/se-springpython-py/tags/
springpython-release-0.8.0/dependencies) used by Spring Python. You
can either follow this link, and download a binary copy of these
libraries, or type:

easy_install amara

This should install amara 1.2.

Due to the changes both in IoC container configuration as well as
terminology, it is highly recommended you read the updated
documentation, especially 
http://springpython.webfactional.com/reference/html/objects.html.

Release Notes - Spring Python - Version 0.8

** Bug
* [SESPRINGPYTHONPY-72] - PetClinic broke in distributed mode.
* [SESPRINGPYTHONPY-77] - Intercepted methods cannot handle having
arguments that are also intercepted

** Improvement
* [SESPRINGPYTHONPY-55] - Include redistributable 3rd party components
as part of distribution
* [SESPRINGPYTHONPY-59] - Integrate Spring Python publishing with
Amazon S3
* [SESPRINGPYTHONPY-71] - SP uses RowCallbackHandler like RowMapper

** New Feature
* [SESPRINGPYTHONPY-66] - Add support for nested component definitions
in XML application configuration
* [SESPRINGPYTHONPY-67] - Add support for constructor-arg dependency
injection

** Refactoring
* [SESPRINGPYTHONPY-68] - Refactor core container

Links:

* For more information, please visit the website at
http://springpython.webfactional.com.

* Framework download at 
http://s3browse.com/getObject/dist.s...RELEASE.tar.gz

* Sample applications at 
http://s3browse.com/getObject/dist.s...RELEASE.tar.gz

* For general browsing of Spring Python releases, visit
http://s3browse.com/explore/dist.spr...ringpython-py/


Key Features of Spring Python include:

* Inversion Of Control - The idea is to decouple two classes at
the interface level. This lets you build many reusable parts in your
software, and your whole application becomes more pluggable. You can
use either the XmlApplicationContext or the
DecoratorBasedApplicationContext.

* Aspect-oriented Programming - Spring Python provides great ways
to wrap advice around objects. It is utilized for remoting. Another
use is for debug tracers and performance tracing.

* DatabaseTemplate - Reading from the database requires a
monotonous cycle of opening cursors, reading rows, and closing
cursors, along with exception handlers. With this template class, all
you need is the SQL query and row-handling function. Spring Python
does the rest.

* Database Transactions - Wrapping multiple database calls with
transactions can make your code hard to read. This module provides
multiple ways to define transactions without making things
complicated.

* Security - Plugin security interceptors to lock down access to
your methods, utilizing both authentication and domain authorization.

* Remoting - It is easy to convert your local application into a
distributed one. If you have already built your client and server
pieces using the IoC container, then going from local to distributed
is just a configuration change.

* Samples - to help demonstrate various features of Spring Python,
some sample applications have been created:
  o PetClinic - Everybody's favorite Spring sample application
has been rebuilt from the ground up using various web containers
including: CherryPy. Go check it out for an example of how to use this
framework.
  o Spring Wiki - Wikis are powerful ways to store and manage
content, so we created a simple one as a demo!
  o Spring Bot - Use Spring Python to build a tiny bot to
manage the IRC channel of your open source project.
--
http://mail.python.org/mailman/listinfo/python-list


.pyc keeps running and never stops

2008-11-06 Thread David Shi
Dear All,
 
I am using Python 2.5 and used py_compile to produce a .pyc file.  The script 
runs well.  However, the .pyc keeps running and never stops.
 
Advices will be deeply appreciated.
 
Regards.
 
David



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


Re: Problem with shelve

2008-11-06 Thread Paul Rudin
[EMAIL PROTECTED] writes:

 Hi all,

 I am trying to use the shelve module to save an object of a 'Electron'
 class I made into a file. The writing goes well but the reading goes :

 e=f['0']
 Traceback (most recent call last):
   File stdin, line 1, in module
   File shelve.py, line 113, in __getitem__
 value = Unpickler(f).load()
 AttributeError: 'module' object has no attribute 'Electron'

 any idea of what I am doing wrong?

I'm not sure, but shelve uses pickle, and to unpickle you need to have
the module and class definition available for import at unpickling
time. The error message suggests that the module is there, but it no
longer contains a definition for the Electron class.

I could be wrong tho' :)

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


Re: Weird behavior with lexical scope

2008-11-06 Thread skip

 def __init__(self, Inner=Inner):
Steve Ok, the Inner=Inner trick works. What the heck does that do, anyway?
Steve I've never seen that formulation.

Understanding that will put you on the path to scoping enlightenment.
Consider when that default assignment is established and how that might
differ from the assignment that occurs when __init__ is called.

Skip

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


Re: Spring Python 0.8.0 has been released/Spring Python goes green

2008-11-06 Thread Goldfish
The Links section has some faults in it. Here is a corrected copy:

Links:

For more information, please visit the website at 
http://springpython.webfactional.com

Framework download at
http://s3browse.com/getObject/dist.springframework.org/release/EXT/se-springpython-py/springpython-0.8.0-RELEASE.tar.gz

Sample applications at
http://s3browse.com/getObject/dist.springframework.org/release/EXT/se-springpython-py/springpython-samples-0.8.0-RELEASE.tar.gz

For general browsing of Spring Python releases, visit
http://s3browse.com/explore/dist.springframework.org/release/EXT/se-springpython-py/
--
http://mail.python.org/mailman/listinfo/python-list


Re: More __init__ methods

2008-11-06 Thread Mr . SpOOn
On Thu, Nov 6, 2008 at 4:59 PM, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] 
wrote:
 class A(object):
def __init__(self, a, b, c):
self.a = a
# ...

@classmethod
def from_string(cls, s):
# ...
return cls(a, b, c)

Thanks.
I think it's time to study decorators.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Red Hat 32 bit RPM for python 2.4+

2008-11-06 Thread Michael Torrie
Pravin Sinha wrote:
 Hi Michael ,
 
 Actually my requirement is to use 32 bit version of pyOpenSSL on 64
 bit linux machine, Python 64 bit is not able to load 32 bit
 pyOpenSSL, so I wanted to install 32 bit python on 64 bit Linux.
 
 Again building that locally is not straight forward as I guess we
 need to use 32 bit version of lib and gcc .
 
 Could you please suggest me something?

I could be wrong, but your choices are:

a) build a custom 32-bit python install to /opt/python32 or something

or

b) set up a 32-bit chroot environment and install the stock 32-bit
python in that.


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


Re: Snippets management

2008-11-06 Thread Stef Mientki

Edwin wrote:

Hi there,

I've been looking for a snippet manager and found PySnippet but it
requires PyGTK. Do you know any other option that doesn't need much? 


I'm sort of new to python and user interfaces seem a bit far for me
right now, that's why I thought having to install PyGTK was
unnecessary.

Would you recommend installing it anyway? 


I'm on a Mac, maybe some users of Steve's Unix flavour know about a
snippets software piece? I'm looking for free/open source alternatives.

Thank you!

P.S.: I'm also new to usenet ;) and hope my english is not that bad.
--
http://mail.python.org/mailman/listinfo/python-list
  


I developed one in wxPython, you can see some of the features here.
 http://mientki.ruhosting.nl/data_www/pylab_works/pw_code_editor.html

Although it's part of a larger part it can be used standalone,
but then it requires two actions copy and paste.
Started from a python application you can do copy+paste with just one 
action.

It has integrated a full blown scintilla editor,
with syntax highlighting, code completion, and syntax checker.

If there's interest, I can distribute the files as a separate package.

cheers,
Stef Mientki

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


Re: More __init__ methods

2008-11-06 Thread Tim Golden

Mr.SpOOn wrote:

On Thu, Nov 6, 2008 at 4:59 PM, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] 
wrote:

class A(object):
   def __init__(self, a, b, c):
   self.a = a
   # ...

   @classmethod
   def from_string(cls, s):
   # ...
   return cls(a, b, c)


Thanks.
I think it's time to study decorators.



While that's no bad thing, you don't really need to do
that simply to understand these examples: they're just
saying do whatever you need to to make these method
class methods, not instance methods.

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


Re: CGI Python problem

2008-11-06 Thread Tim Chase

Here is the permissions, which I think are definitely right now:

drwxrwxrwx   8   4.0K Nov  6 13:34 public_html/

drwxrwxrwx   2   4.0K Nov  6 13:35 cgi-bin/ [inside public_html]

-rw-r-xr-x  1    117 Nov  6 11:39 test_pl.cgi* [inside cgi-bin]
-rw-r-xr-x  1    168 Nov  6 13:35 test_py.cgi* [inside cgi-bin]


Those indeed look kosher


note both have *.cgi extensions otherwise plain text is shown.


I prefer to use .py (or .pl) for the extensions so my editors 
pick up the syntax...In my server's CGI directory, as long as the 
+x bits are set, it runs them with the .py extension.  However, 
that's an aesthetic matter.



Also I think I should be getting a traceback since I used import
cgitb; cgitb.enable() I wonder does this suggest the python
interpreter hasn't be found?


It's certainly something to check...Apache may run in a chroot'ed 
environment where Perl may be available, and Python may not (or 
it may be someplace else in the chroot environment).


If you've got Perl hacking skills, you might throw together a 
simple perl-script that checks to see if /usr/bin/python exists 
where you think it is, or walks the directory tree returning the 
path of files containing the word python. My perl skills are 
close to non-existent (only having reverse-engineered some 
hand-me-down perl code)



Also I'm not sure how to check if the server is running mod_perl?


I think that's usually (assuming your admin hasn't munged them) 
included in the headers returned from the server, or if you've 
got PHP installed in the same setup, you can create a simple PHP 
page to dump the info (with this one line in it):


  ?php phpinfo();?

which should include a line for the modules loaded in Apache.

Hope this gives you a few more things to check,

-tkc




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


Re: SocketServer shutdown deadlock

2008-11-06 Thread Okko Willeboordse
If I wait until _BaseServer__serving is True before calling shutdown
things go better.



Okko Willeboordse wrote:
 All,
 
 With Python 2.5 SocketServer features the shutdown method that can be
 called from another thread to stop the serve_forever loop.
 
 However;
 
 When the shutdown method is called before serve_forever, shutdown will
 never return.
 This can happen when a server is stopped during startup.
 
 In other words, the following program shouldn't hang but it does;
 
 import SocketServer
 
 server = SocketServer.ThreadingTCPServer((127.0.0.1, 12345),
 SocketServer.BaseRequestHandler)
 server.shutdown()
 
 What to do?

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


Re: More __init__ methods

2008-11-06 Thread Mr . SpOOn
On Thu, Nov 6, 2008 at 7:44 PM, Tim Golden [EMAIL PROTECTED] wrote:
 While that's no bad thing, you don't really need to do
 that simply to understand these examples: they're just
 saying do whatever you need to to make these method
 class methods, not instance methods.

Yes.

I think this changes the design of my class.

I mean, till now I had something like:

class foo:
def __init__(self, string=None, integer=None, someinstance=None):
 self.a = 0
 self.b = 0

 if string:
# do something to calculate a and b
 elif integer:
# do something else to calculate a and b
 ...
 ...

So I used different methods to calculate the same variables.

Now I must pass a and b to the main constructor and calculate them in
the classmethods.

class foo:
def __init__(self, a, b):
 self.a = a
 self.b = b

@classmethod
def from_string(self, ..):
  ...
  ...

What I mean is: I can't use anymore __init__ as the default
constructor, but I always have to specify the way I'm creating my
object. Am I right? I'm asking just to be sure I have understood.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Weird behavior with lexical scope

2008-11-06 Thread Kirk Strauser
At 2008-11-06T16:57:39Z, mrstevegross [EMAIL PROTECTED] writes:

 class Outer:
   class Inner:
 def __init__(self):
   pass
   def __init__ (self):
 a = Inner()
 Outer()

Try instead:

class Outer:
def __init__(self):
a = self.Inner()


-- 
Kirk Strauser
The Day Companies
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-11-06 Thread sturlamolden
On Nov 6, 6:05 pm, Walter Overby [EMAIL PROTECTED] wrote:

 I don't understand how this would help.  If these large data
 structures reside only in one remote process, then the overhead of
 proxying the data into another process for manipulation requires too
 much IPC, or at least so Andy stipulates.

Perhaps it will, or perhaps not. Reading or writing to a pipe has
slightly more overhead than a memcpy. There are things that Python
needs to do that are slower than the IPC. In this case, the real
constraint would probably be contention for the object in the server,
not the IPC. (And don't blame it on the GIL, because putting a lock
around the object would not be any better.)


  3. Go tohttp://pyro.sourceforge.net, download the code and read the
  documentation.

 I don't see how this solves the problem with 2.

It puts Python objects in shared memory. Shared memory is the fastest
form of IPC there is. The overhead is basically zero. The only
constraint will be contention for the object.


 I understand Andy's problem to be that he needs to operate on a large
 amount of in-process data from several threads, and each thread mixes
 CPU-intensive C functions with callbacks to Python utility functions.
 He contends that, even though he releases the GIL in the CPU-bound C
 functions, the reacquisition of the GIL for the utility functions
 causes unacceptable contention slowdowns in the current implementation
 of CPython.

Yes, callbacks to Python are expensive. But is the problem the GIL?
Instead of contention for the GIL, he seems to prefer contention for a
complex object. Is that any better? It too has to be protected by a
lock.


 If I understand them correctly, none of these concerns are silly.

No they are not. But I think he underestimates what multiple processes
can do. The objects in 'multiprocessing' are already a lot faster than
their 'threading' and 'Queue' counterparts.



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


Re: Error importing wxPython

2008-11-06 Thread Ron Reidy
Thank you Chris.  That worked perfectly.

On Thu, Nov 6, 2008 at 9:05 AM, Chris Mellon [EMAIL PROTECTED] wrote:
 On Thu, Nov 6, 2008 at 8:09 AM,  [EMAIL PROTECTED] wrote:
 Hi,

 I just installed wxPython from http://wxpython.org/download.php.  When
 I import (import wx), I get this error:

 ImportError: DLL load failed: The application has failed to start
 because its side-by-side configuration is incorrect. Please see the
 application event log for more detail.

 Has anyone had this problem and how can I resolve it?

 Thanks in advance.


 downloading and installing this package should fix the problem:

 http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BFdisplaylang=en




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


Re: Weird behavior with lexical scope

2008-11-06 Thread [EMAIL PROTECTED]
On Nov 6, 9:57 pm, mrstevegross [EMAIL PROTECTED] wrote:
 I ran into a weird behavior with lexical scope in Python. I'm hoping
 someone on this forum can explain it to me.

 Here's the situation: I have an Outer class. In the Outer class, I
 define a nested class 'Inner' with a simple constructor. Outer's
 constructor creates an instance of Inner. The code looks like this:

 =
 class Outer:
   class Inner:
     def __init__(self):
       pass
   def __init__ (self):
     a = Inner()
 Outer()
 =

 However, the above code doesn't work. The creation of Inner() fails.
 The error message looks like this:

   File /tmp/foo.py, line 12, in module
     Outer()
   File /tmp/foo.py, line 10, in __init__
     a = Inner()
 NameError: global name 'Inner' is not defined

 This surprises me! Since the construction of Inner takes place within
 the lexical scope 'Outer', I assumed the interpreter would search the
 Outer scope and find the 'Inner' symbol. But it doesn't! If I change:
   a = Inner()
 to
   a = Outer.Inner()

 it works fine, though.

AFAIK, when 'Outer.__init__' executes, 'Inner' is first searched for
within 'Outer.__init__()'s local namespace. Since 'Inner' is defined
outside the function namespace, the search will fail. Python then
looks at the module level namespace - where Inner is again not defined
(only 'Outer' is available in the module namespace), the final search
will be in the interpreter global namespace which will fail too. When
you change your code from 'Inner' to 'Outer.Inner', the module level
namespace search will match ( or atleast that's how i think it should
all work :) )

Try this ..

class Outer:
   def __init__(self):
  class Inner:
 def __init__(self): pass
  a = Inner()
Outer()

This should work, because the Outer.__init__ namespace (first
namespace being searched) has Inner defined within it

-srp




 So, can anyone explain to me how Python looks up symbols? It doesn't
 seem to be searching the scopes I expected...

 Thanks,
 --Steve

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


python bug when subclassing list?

2008-11-06 Thread Hamish McKenzie
I want to write a Vector class and it makes the most sense to just subclass 
list.  I also want to be able to instantiate a vector using either:

Vector( 1, 2, 3 )
OR
Vector( [1, 2, 3] )


so I have this:

class Vector(list):
  def __new__( cls, *a ):
try:
  print a
  return list.__new__(cls, a)
except:
  print 'broken'
  return list.__new__(cls, list(a))


doing Vector( 1, 2, 3 ) on this class results in a TypeError - which doesn't 
seem to get caught by the try block (ie broken never gets printed, and it 
never tries to

I can do pretty much the exact same code but inheriting from tuple instead of 
list and it works fine.

is this a python bug?  or am I doing something wrong?

thanks,
-h.


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


Re: Finding the instance reference of an object

2008-11-06 Thread Arnaud Delobelle

I know this thread has grown quite personal for some of its
participants.  I am posting in a spirit of peace and understanding :)

Joe Strout [EMAIL PROTECTED] writes:
[...]
 Um, no, I've admitted that it's a reference all along.  Indeed, that's
 pretty much the whole point: that variables in Python don't contain
 objects, but merely contain references to objects that are actually
 stored somewhere else (i.e. on the heap).  This is explicitly stated
 in the Python docs [1], yet many here seem to want to deny it.

You refer to docs about the *implementation* of Python in C.  This is
irrelevant.

Also, you talk about variables 'containing' something.  In Python,
variables don't contain anything, they're simply names for objects.
'Pass by value' is not relevant to Python as variables do not contain
anything.  'Pass by reference' is not relevant to Python as the language
doesn't have the concept of object reference (in the sense of e.g. C++
reference).

[...]
 Calling by value is not a useful definition of Pythons behaviour.

 It really is, though.  You have to know how the formal parameter
 relates to the actual parameter.  Is it a copy of it, or an alias of
 it?  Without knowing that, you don't know what assignments to the
 formal parameter will do, or even what sort of arguments are valid.
 Answer: it's a copy of it.  Assignments don't affect the actual
 parameter at all.  This is exactly what call by value means.

Here lies, IMHO, the reason why you think you need Python to 'pass by
value'.  As you believe that variables must contain something, you think
that assignment is about copying the content of a variable.  Assignment
in Python is simply giving a new name to an object.

To understand variables (which I prefer to call 'names') and function
calls in Python you need simply to understand that:

  - a variable is a name for an object
  - assignment is naming an object
  - the parameters of a function are local names for the call arguments
(I guess 'pass by object' is a good name).

Now quoting the start of your post:

 On Nov 4, 2008, at 12:57 PM, Hendrik van Rooyen wrote:
 5. You see that the first three languages above are passing a
 reference by value and using that to mutate and object, yet for
 reasons still mysterious, the Python example (which has exactly the
 same behavior) must be doing something different.

 This is dialectic nit picking - WTF makes passing a reference by
 value
 different from passing a reference - the salient point is that its
 a reference
 that is passed

I would say that an oject is passed, not a reference.

 I know it seems nit-picky on the surface, but it is important.  It is
 the distinction that lets you answer whether:

 def foo(x):
x = Foo()

 x = Bar()
 foo(x)

 ...results in x (after the call) now referring to a Foo, or still
 referring to a Bar.

You don't need this to decide.  This is what happens:

x = Bar() # Call this new Bar object 'x'
foo(x)# call function foo with argument the object known as 'x'

# Now, in foo:
def foo(x):   # Call 'x' locally the object passed to foo
x = Foo() # Call 'x' locally this new Foo object.

Obviously after all this, 'x' is still the name of the Bar object
created at the start.


To sum up: for 'pass by value' to make sense in Python you need to
create an unnecessarily complex model of how Python works.  By letting
go of 'pass by value' you can simplify your model of the language
(keeping it correct of course) and it fits in your brain more easily.

Of course your own model is valid but there is a better one which is
easier to grasp for people without a background in C/C++ - like
languages.

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


List to Text back to List

2008-11-06 Thread SimonPalmer
Hi, I am looking for a way to convert a List of floating point numbers
to and from text.  I am embedding it in an XML document and am looking
for a neat way to serialise and de-serialise a list from a text node.
I can easily write something to do it manually but I wondered whether
List had native support to go to and from text.

If not List, are there any other collections/arrays that do this?

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


Re: python bug when subclassing list?

2008-11-06 Thread Arnaud Delobelle
Hamish McKenzie [EMAIL PROTECTED] writes:

 I want to write a Vector class and it makes the most sense to just
 subclass list.  I also want to be able to instantiate a vector using
 either:

 Vector( 1, 2, 3 )
 OR
 Vector( [1, 2, 3] )


 so I have this:

 class Vector(list):
 def __new__( cls, *a ):
 try:
 print a
 return list.__new__(cls, a)
 except:
 print 'broken'
 return list.__new__(cls, list(a))


 doing Vector( 1, 2, 3 ) on this class results in a TypeError - which
 doesn't seem to get caught by the try block (ie broken never gets
 printed, and it never tries to

 I can do pretty much the exact same code but inheriting from tuple
 instead of list and it works fine.

 is this a python bug?  or am I doing something wrong?

You're doing something wrong!

When you call Vector.__new__(cls, *a), this creates a new list object
(call it L) and then calls Vector.__init__(L, *a) automatically, falling
back to list.__init__(L, *a) (which won't work when a has more than one
element).  In fact list initialisation is done in list.__init__, not in
list.__new__ (as opposed to tuple initialisation because tuples are
immutable).

A solution:

 class Vector(list):
... def __init__(self, *args):
... try:
... list.__init__(self, *args)
... except TypeError:
... list.__init__(self, args)
... 
 Vector([1,2,3])
[1, 2, 3]
 Vector(1,2,3)
[1, 2, 3]
 Vector(1)
[1]
 Vector()
[]

HTH

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


Re: List to Text back to List

2008-11-06 Thread Chris Rebert
On Thu, Nov 6, 2008 at 12:04 PM, SimonPalmer [EMAIL PROTECTED] wrote:
 Hi, I am looking for a way to convert a List of floating point numbers
 to and from text.  I am embedding it in an XML document and am looking
 for a neat way to serialise and de-serialise a list from a text node.
 I can easily write something to do it manually but I wondered whether
 List had native support to go to and from text.

 If not List, are there any other collections/arrays that do this?

It's not really a matter of the collection, but more a matter of
serialization format/library.

If you want the serialized representation to be human-readable, use
JSON (http://docs.python.org/library/json.html#module-json).
If that's not a requirement, use pickle
(http://docs.python.org/library/pickle.html#module-pickle).
Both modules can convert simple Python data, such as your list of
floats, to a bytestream and back again.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com


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

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


Re: List to Text back to List

2008-11-06 Thread SimonPalmer
On Nov 6, 8:11 pm, Chris Rebert [EMAIL PROTECTED] wrote:
 On Thu, Nov 6, 2008 at 12:04 PM, SimonPalmer [EMAIL PROTECTED] wrote:
  Hi, I am looking for a way to convert a List of floating point numbers
  to and from text.  I am embedding it in an XML document and am looking
  for a neat way to serialise and de-serialise a list from a text node.
  I can easily write something to do it manually but I wondered whether
  List had native support to go to and from text.

  If not List, are there any other collections/arrays that do this?

 It's not really a matter of the collection, but more a matter of
 serialization format/library.

 If you want the serialized representation to be human-readable, use
 JSON (http://docs.python.org/library/json.html#module-json).
 If that's not a requirement, use pickle
 (http://docs.python.org/library/pickle.html#module-pickle).
 Both modules can convert simple Python data, such as your list of
 floats, to a bytestream and back again.

 Cheers,
 Chris
 --
 Follow the path of the Iguana...http://rebertia.com



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



I looked at pickle, but the problem is that I want my XML to be
readable by languages other than python, so it sort of precludes it.
JSON would be perfect, but I think the module only exists in 2.6, is
that right?  Unfortunately I am bound to 2.4.

It is looking more and more like I am going to have to roll my own.
--
http://mail.python.org/mailman/listinfo/python-list


Re: List to Text back to List

2008-11-06 Thread Chris Rebert
On Thu, Nov 6, 2008 at 12:18 PM, SimonPalmer [EMAIL PROTECTED] wrote:
 On Nov 6, 8:11 pm, Chris Rebert [EMAIL PROTECTED] wrote:
 On Thu, Nov 6, 2008 at 12:04 PM, SimonPalmer [EMAIL PROTECTED] wrote:
  Hi, I am looking for a way to convert a List of floating point numbers
  to and from text.  I am embedding it in an XML document and am looking
  for a neat way to serialise and de-serialise a list from a text node.
  I can easily write something to do it manually but I wondered whether
  List had native support to go to and from text.

  If not List, are there any other collections/arrays that do this?

 It's not really a matter of the collection, but more a matter of
 serialization format/library.

 If you want the serialized representation to be human-readable, use
 JSON (http://docs.python.org/library/json.html#module-json).
 If that's not a requirement, use pickle
 (http://docs.python.org/library/pickle.html#module-pickle).
 Both modules can convert simple Python data, such as your list of
 floats, to a bytestream and back again.

 Cheers,
 Chris
 --
 Follow the path of the Iguana...http://rebertia.com



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



 I looked at pickle, but the problem is that I want my XML to be
 readable by languages other than python, so it sort of precludes it.
 JSON would be perfect, but I think the module only exists in 2.6, is
 that right?  Unfortunately I am bound to 2.4.

 It is looking more and more like I am going to have to roll my own.

The module is available as a third-party library for previous Python
versions at http://www.undefined.org/python/

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: List to Text back to List

2008-11-06 Thread Arnaud Delobelle
SimonPalmer [EMAIL PROTECTED] writes:


 I looked at pickle, but the problem is that I want my XML to be
 readable by languages other than python, so it sort of precludes it.
 JSON would be perfect, but I think the module only exists in 2.6, is
 that right?  Unfortunately I am bound to 2.4.

Simpljson is a package for python 2.3+:

http://pypi.python.org/pypi/simplejson/

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


Re: More __init__ methods

2008-11-06 Thread Larry Bates

Mr.SpOOn wrote:

On Thu, Nov 6, 2008 at 7:44 PM, Tim Golden [EMAIL PROTECTED] wrote:

While that's no bad thing, you don't really need to do
that simply to understand these examples: they're just
saying do whatever you need to to make these method
class methods, not instance methods.


Yes.

I think this changes the design of my class.

I mean, till now I had something like:

class foo:
def __init__(self, string=None, integer=None, someinstance=None):
 self.a = 0
 self.b = 0

 if string:
# do something to calculate a and b
 elif integer:
# do something else to calculate a and b
 ...
 ...

So I used different methods to calculate the same variables.

Now I must pass a and b to the main constructor and calculate them in
the classmethods.

class foo:
def __init__(self, a, b):
 self.a = a
 self.b = b

@classmethod
def from_string(self, ..):
  ...
  ...

What I mean is: I can't use anymore __init__ as the default
constructor, but I always have to specify the way I'm creating my
object. Am I right? I'm asking just to be sure I have understood.


Is there some reason not to use something like the following?

class foo:
def __init__(self, val):
self.a = 0
self.b = 0

if isinstance(val, basestring):
#
# do something to calculate a and b
#

elif isintance(val, int):
#
# do something else to calculate a and b
#

elif isinstance(val, someinstance)
#
# do something else to calculate a and b
#

else:
#
# Don't know what to do with unknown type
#
raise ValueError()



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


Re: locating the chorus in a MIDI song?

2008-11-06 Thread Aaron Brady
On Nov 3, 10:20 pm, Joe Strout [EMAIL PROTECTED] wrote:
 We've got a need to generate short samples of songs that are in MIDI  
 format, to provide a preview function in a web app.  We'd like to do  
 something more clever than just taking the middle 20 seconds (or  
 whatever) of the song -- ideally, we'd like to find the chorus, since  
 that's likely to be the most easily recognized part of the song.

 I believe this could be done fairly reliably by looking for patterns  
 in the MIDI file, though I'm sure there are plenty of complications to  
 this simple idea.

Hi Joe, nice to hear from you from earlier discussion.

Would it be applicable to mark one chorus by hand, and the program
finds all the others?
--
http://mail.python.org/mailman/listinfo/python-list


Re: More __init__ methods

2008-11-06 Thread Ben Finney
Mr.SpOOn [EMAIL PROTECTED] writes:

 On Thu, Nov 6, 2008 at 4:59 PM, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] 
 wrote:
  class A(object):
 def __init__(self, a, b, c):
 self.a = a
 # ...
 
 @classmethod
 def from_string(cls, s):
 # ...
 return cls(a, b, c)
 
 Thanks.
 I think it's time to study decorators.

Studying decorators is a good idea, but in this instance it's not
necessary. The above is merely using decorator syntax to apply the
‘classmethod’ type to a function.

All you need to know to understand the above is that it will have
essentially the same result as:

class A(object):
# ...

def _from_string(cls, s):
# ...
return cls(a, b, c)
from_string = classmethod(_from_string)
del _from_string

without the intermediate binding of the ‘_from_string’ name.

-- 
 \  “The best way to get information on Usenet is not to ask a |
  `\   question, but to post the wrong information.” —Aahz |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to re-import a function from a module?

2008-11-06 Thread Aaron Brady
On Nov 5, 7:36 pm, Kurda Yon [EMAIL PROTECTED] wrote:
 Hi,

 I have the following small problem. I run Python interactively. In the
 beginning of the run I import many functions from many modules. Than I
 execute some commands and notice that one of the imported functions
 contains a mistake. I open another terminal in which I open the file
 with the problematic function and correct the function. However, the
 Python does not see my changes. It still uses the old version of the
 function. In principle I could close the Python session and reopen it
 again and import all functions agane. But it does not seem to be a
 convenient solution. Is there a way to force Python to re-import the
 function, i.e. to force it to use the new version of the function?

 Thank you in advance.

Here is another option.

Look at the InteractiveConsole class.  When you make a change, run the
command:

 changed

Your subclass of InteractiveConsole catches it and does not send it to
the compiler.  Instead, it closes and reruns the entire session so
far.  Or, just the imports and definitions, which you have to detect
by hand.  This is probably the hard way.
--
http://mail.python.org/mailman/listinfo/python-list


Re: More __init__ methods

2008-11-06 Thread Arnaud Delobelle
Ben Finney [EMAIL PROTECTED] writes:
[...]
 All you need to know to understand the above is that it will have
 essentially the same result as:

 class A(object):
 # ...

 def _from_string(cls, s):
 # ...
 return cls(a, b, c)
 from_string = classmethod(_from_string)
 del _from_string

 without the intermediate binding of the ‘_from_string’ name.

So you mean it is the same as:

class A(object):
# ...

def from_string(cls, s):
# ...
from_string = classmethod(from_string)

:)

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


Re: More __init__ methods

2008-11-06 Thread Ben Finney
Mr.SpOOn [EMAIL PROTECTED] writes:

 class foo:
 def __init__(self, a, b):
  self.a = a
  self.b = b
 
 @classmethod
 def from_string(self, ..):
   ...
   ...
 
 What I mean is: I can't use anymore __init__ as the default
 constructor, but I always have to specify the way I'm creating my
 object. Am I right? I'm asking just to be sure I have understood.

Yes, that's what the above design requires. You code ‘foo.__init__’
for the common use case, and create ‘foo.from_bar’ classmethod factory
functions for other cases. The caller then needs to specify which case
is being requested.

-- 
 \ “I was in the first submarine. Instead of a periscope, they had |
  `\   a kaleidoscope. ‘We're surrounded.’” —Steven Wright |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Step-by-step exec

2008-11-06 Thread Aaron Brady
On Nov 6, 7:11 am, [EMAIL PROTECTED] wrote:
 On Nov 6, 1:02 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:

  On Nov 6, 4:27 pm, [EMAIL PROTECTED] wrote:

   Hi,

   I am using a small python file as an input file (defining constants,
   parameters, input data, ...) for a python application.
   The input file is simply read by an exec statement in a specific
   dictionary, and then the application retrieve all the data it need
   from the dictionary...
   Everything is working nicely, but I'd like to have something a little
   bit more robust regarding input file errors: now
   any error in the python input script raise an exception and stop the
   execution.
   What I am trying to do is to execute it step-by-step, so that I can
   capture the exception if one line (or multi-line statement) fails,
   print a warning about the failure, and continue the execution fo the
   following lines/statements. Of course, an error on one line can
   trigger errors in the following lines, but it does not matter in the
   application I have in mind, the goal is to parse as much of the input
   script as possible, warn about the errors, and check what's inside the
   dictionary after the exec.
   One way to do it is to read the input script line per line, and exec
   each line in turn. However, this is not convenient as it does not
   allow multi-line statements, or basic control flow like if - else
   statements or loops.

  Do you have control over the input file generation ? If the input file
  can be easily divided into self sufficient blocks of code, you could
  read each block in one at a time and do a compile() and exec(). Your
  input file need not be a full python script too, you could just have
  token delimited blocks of python code which are read in 1 block at a
  time and then exec().

  -srp

   Is there a better way for a step-by-step exec? Syntax errors in the
   input script are not really a problem (as it is generated elsewhere,
   it is not directly edited by users), although it would be nice to
   catch. The biggest problem are runtime errors (attribute error, value
   error, ...). Maybe compiling the file into a code object, and
   executing this code object step-by-step in a way similar to debug? pdb
   module should do something similar

   Best regards,

   Greg.

 Thanks for your input!
 I had a similar solution in mind (with continuation comments to be
 able to read multi-line statements, instead of statement delimiters,
 but
 I think your delimiter idea would be easier to implement).
 The only problem is that files generated by current and older version
 of the input generator (which do not have any kind of statement
 delimiter)
 will not be readable, or, if we just consider old file as one big
 statement, will not offer the step-by-step execution. It would work
 nice with new files,
 but the best solution would be something that work also with older
 auto-generated files...

 In fact, the error in the input script are mainly caused by version
 mismatch, and the step-by-step approach is
 mainly for improving backward compatibility.
 Having better backward compatibility starting from now on would be
 nice, but having backward compatibility with previous versions would
 be even better ;-)
 contains multi-line statements

Check out the InteractiveConsole and InteractiveInterpreter classes.
Derive a subclass and override the 'push' method.  It's not documented
so you'll have to examine the source to find out exactly when and what
to override.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Plz help..SocketServer UDP server losing lots of packets

2008-11-06 Thread Steve Holden
I D wrote:
 Hello James,
 Thanks for your response.
 But I cannot use a third party software, I need to use the exisiting
 API's within python.
 As I am new to python, I suspected that I should go by a simpler
 approach and so
 scrapped off the below code and wrote a very simple UDP server code as
 follows:
  
 logFileName = '/home/msat/gsc/logs/' + compNum + '/logparsertracedump.log'
 logfile = open(logFileName, w)
 from socket import *
 host = 121.3.0.1 http://121.3.0.1
 port = PORT
 buf = 4096
 addr = (host,port)
 # Create socket and bind to address
 UDPSock = socket(AF_INET,SOCK_DGRAM)
 UDPSock.setsockopt(SOL_SOCKET, SO_RCVBUF, 8388608)
 UDPSock.bind(addr)
 while 1:
 data,addr = UDPSock.recvfrom(buf)
 if not fileExists(logFileName):
 logfile = open(logFileName, a)
 logfile.writelines(data)

It would make more sense to leave the file open outside the loop. If
it's important to have each packet individually logged you can call the
file's .flush() method after each .writelines() call. No need to
continually re-open it. I doubt this is the source of your packet loss,
however. Maybe there's a bug in fileExists (for which you could have
used os.path.exists, by the way).

 # Close socket
 UDPSock.close()
  
How do you anticipate this line will ever be executed?

Your network code looks basically OK, though a little horrible with
things like 8388608 for the socket options. See if you get any ideas from

  http://holdenweb.com/docs/NetProg.pdf

though it doesn't tell you much you don't appear to know already.

regards
 Steve

 Even this seems to lose packets, I would really appreciate if any
 pointers can be provided to improve my code.
 
 Thanks,
 Sam
  
 On Wed, Nov 5, 2008 at 7:46 PM, James Mills
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:
 
 On Thu, Nov 6, 2008 at 9:53 AM,  [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:
  logFileName = 'log.txt'
 logfile = open(logFileName, a)
 class MyUDPServer(SocketServer.UDPServer):
 def server_bind(self):
 self.socket.setsockopt(socket.SOL_SOCKET,
  socket.SO_RCVBUF, 8388608)
 self.socket.bind(self.server_address)
 
 class LogsDumpHandler(SocketServer.DatagramRequestHandler):
 def handle(self):
 global logfile
  # fileExists is a function which checks the existence of a file
 if not fileExists(logFileName):
 logfile = open(logFileName, a)
 logfile.writelines(self.rfile.readlines())
 
 server = MyUDPServer((,PORT), LogsDumpHandler)
 server.serve_forever()
 logfile.close()
 
 This is horrible code :/
 
 Try these instead:
  * UDPServer -
 http://trac.softcircuit.com.au/circuits/browser/examples/udpserver.py
  * UDPClient  -
 http://trac.softcircuit.com.au/circuits/browser/examples/udpclient.py
 
 Example usage
 --
 
 ~/circuits/examples
 $ ./udpserver.py
 127.0.0.1 http://127.0.0.1/, 9000:
 test
 127.0.0.1 http://127.0.0.1/, 9000:
 hi
 
 ~/circuits/examples
 $ ./udpclient.py -b 127.0.0.1:9000 http://127.0.0.1:9000/
 127.0.0.1:8000 http://127.0.0.1:8000/
 test
 127.0.0.1 http://127.0.0.1/, 8000:
 test
 hi
 127.0.0.1 http://127.0.0.1/, 8000:
 hi
 
 You can download circuits from http://trac.softcircuit.com.au/circuits/
 or get the latest development version by using Mercurial (1):
 hg clone http://hg.softcircuit.com.au/projects/circuits/
 
 cheers
 James
 
 [1] http://www.selenic.com/mercurial/wiki/
 
 --
 --
 -- Problems are solved by method
 
 
 
 
 
 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: I need a simple windows form handle.

2008-11-06 Thread Aaron Brady
On Nov 6, 7:50 am, 一首诗 [EMAIL PROTECTED] wrote:
 Hi all,

 Today I was writing a simple test app for a video decoder library.

 I use python to parse video files and input data to the library.

 I got a problem here,  I need a windows form, and send the form handle
 to the library as a parameter, then it can output video on the form.

 Here is my problem:

   What is the simplest way to get a windows form which has a handle?

 I tried to use win32py but it seems to be to complicate for my
 purpose.
 And the form would block the main thread even if I call its DoModal
 method on another thread.

 =

 PS: Finally I decided I can not finish it today so I write a WinForm
 App in C# in 5 minutes and send video from my python app to it by UDP.

 That works.

Why don't you write the GUI in Python?  Check out 'wxPython' and
others.  'wx' programs can get pretty short, something like:

app= wx.PySimpleApp()
frame= wx.Frame( app )
canvas= wx.Canvas( frame )
canvas.Render( my_picture )
app.MainLoop()
--
http://mail.python.org/mailman/listinfo/python-list


Re: List to Text back to List

2008-11-06 Thread Aaron Brady
On Nov 6, 2:18 pm, SimonPalmer [EMAIL PROTECTED] wrote:
 On Nov 6, 8:11 pm, Chris Rebert [EMAIL PROTECTED] wrote:



  On Thu, Nov 6, 2008 at 12:04 PM, SimonPalmer [EMAIL PROTECTED] wrote:
   Hi, I am looking for a way to convert a List of floating point numbers
   to and from text.  I am embedding it in an XML document and am looking
   for a neat way to serialise and de-serialise a list from a text node.
   I can easily write something to do it manually but I wondered whether
   List had native support to go to and from text.

   If not List, are there any other collections/arrays that do this?

  It's not really a matter of the collection, but more a matter of
  serialization format/library.

  If you want the serialized representation to be human-readable, use
  JSON (http://docs.python.org/library/json.html#module-json).
  If that's not a requirement, use pickle
  (http://docs.python.org/library/pickle.html#module-pickle).
  Both modules can convert simple Python data, such as your list of
  floats, to a bytestream and back again.

  Cheers,
  Chris
  --
  Follow the path of the Iguana...http://rebertia.com

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

 I looked at pickle, but the problem is that I want my XML to be
 readable by languages other than python, so it sort of precludes it.
 JSON would be perfect, but I think the module only exists in 2.6, is
 that right?  Unfortunately I am bound to 2.4.

 It is looking more and more like I am going to have to roll my own.

There is PyYAML, yet-another-markup-language.  Bindings go all the way
back to 2.3.

http://pyyaml.org/wiki/PyYAML

You can always just do ' '.join( alist ) to store, and
astring.split( ) to load.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >