Python classes at USENIX Tech - June 14-15, 2009

2009-05-20 Thread David Beazley

Python Training Opportunities
 In San Diego at the 2009 USENIX Technical Conference
   June 14-15, 2009

  http://www.usenix.org/events/usenix09/training/index.html

I'm pleased to announce three Python tutorial sessions to be
presented at the 2009 USENIX Technical Conference in San Diego.

The Python Programming Language, June 14, 2009  (All Day)
-
This tutorial provides a comprehensive tour of the Python programming
language and shows how it can be used to solve a variety of practical
problems. The tutorial will illustrate important concepts through
examples that primarily focus on data analysis, systems programming,
and system administration.

Introduction to Python Concurrency, June 15, 2009 (Morning)
---
A overview of the state of concurrent programming in Python.  Topics
include threads, message passing, multiprocessing, asynchronous I/O,
and coroutines.

Python Generator Hacking, June 15, 2009 (Afternoon)
---
Generators and generator expressions are among the most useful
features of Python. Yet many Python programmers are unsure how to
apply them to real-world problems. This tutorial presents practical
uses of generators, including processing large data files, handling
real-time data sequences, parsing, threads, networking, and
distributed computing.

More information about these courses and the USENIX Tech Conference is
available at:

http://www.usenix.org/events/usenix09

Hopefully, I'll see you in San Diego!

Cheers,
Dave
--
David Beazley (http://www.dabeaz.com)
Author Python Essential Reference

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

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


Join us for Scientific Computing with Python Webinar

2009-05-20 Thread Travis Oliphant


Hello all Python users:

I am pleased to announce the beginning of a free Webinar series that  
discusses using Python for scientific computing.   Enthought will host  
this free series  which will take place once a month for 30-45  
minutes.   The schedule and length may change based on participation  
feedback, but for now it is scheduled for the fourth Friday of every  
month. This free webinar should not be confused with the EPD  
webinar on the first Friday of each month which is open only to  
subscribers to the Enthought Python Distribution.


I (Travis Oliphant) will be the first speaker at this continuing  
series.  I plan to present a brief (10-15) minute talk on reading  
binary files with NumPy using memory mapped arrays and structured data- 
types.  This talk will be followed by a demonstration of Chaco for  
interactive 2-d visualization and Mayavi for interactive 3-d  
visualization.   Both Chaco and Mayavi are open-source tools and part  
of the Enthought Tool Suite.  They can be conveniently installed using  
the Enthought Python Distribution.   Topics for future webinars will  
be chosen later based on participant feedback.


This event will take place on Friday at 3:00pm CDT and will last 30 to  
45 minutes depending on questions asked.   Space is limited at this  
event.   If you would like to participate, please register by going to https://www1.gotomeeting.com/register/422340144 
 or by clicking on the appropriate link in the attached announcement.


There will be a 10 minute technical help session prior to the on-line  
meeting which you should plan to use if you have never participated in  
a GoToWebinar previously.  During this time you can test your  
connection and audio equipment as well as familiarize yourself with  
the GoTo Meeting software.


I am looking forward to interacting with many of you this Friday.

Best regards,

Travis Oliphant
Enthought, Inc.


Enthought is the company that sponsored the creation of SciPy and the  
Enthought Tool Suite.  It continues to sponsor the SciPy community by  
hosting the SciPy mailing list and website and participating in the  
development of SciPy and NumPy.  Enthought creates custom  
scientific and technical software applications and provides training  
on using Python for technical computing.   Enthought also provides the  
Enthought Python Distribution.   Learn more at http://www.enthought.com


Travis Oliphant's bio can be read at 
http://www.enthought.com/company/executive-team.php








Scientific Computing with Python Webinar





Each webinar in this continuing series will demonstrate the use of  
some aspect of Python to assist with scientific, engineering, and  
technical computing.   Enthought will host each meeting and select a  
specific topic based on feedback from participants

Register for a session now by clicking a date below:
Fri, May 22, 2009 3:00 PM - 3:30 PM CDT
Fri, Jun 19, 2009 1:00 PM - 1:30 PM CDT
Fri, Jul 17, 2009 1:00 PM - 1:30 PM CDT
Once registered you will receive an email confirming your registration
with information you need to join the Webinar.
System Requirements
PC-based attendees
Required: Windows® 2000, XP Home, XP Pro, 2003 Server, Vista
Macintosh®-based attendees
Required: Mac OS® X 10.4 (Tiger®) or newer









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

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


EPD 4.3.0 released

2009-05-20 Thread Ilan Schnell
I am pleased to announce that EPD (Enthought Python Distribution) version
4.3.0 has been released.  You may find more information about EPD, as
well as download a 30 day free trial here:

http://www.enthought.com/products/epd.php

You can check out the release notes here:

https://svn.enthought.com/epd/wiki/Py25/4.3.0/RelNotes

The main point of this release was to update NumPy and SciPy to the latest
versions and to introduce the ability to install, update and rollback
packages
using our package repository (for basic and above subscribers only, please
contact us for username and password).


About EPD
-
The Enthought Python Distribution (EPD) is a kitchen-sink-included
distribution of the Python Programming Language, including over 80
additional tools and libraries. The EPD bundle includes NumPy, SciPy,
IPython, 2D and 3D visualization, database adapters, and a lot of
other tools right out of the box.

http://www.enthought.com/products/epdlibraries.php

It is currently available as a single-click installer for Windows XP and
Vista
(x86), Mac OS X (a universal binary for OS X 10.4 and above),
RedHat 3, 4 and 5 (x86 and amd64), as well as Solaris 10 (x86).

EPD is free for academic use.  An annual subscription including installation
support is available for individual and commercial use.  Additional
support options, including customization, bug fixes and training classes
are also available:

http://www.enthought.com/products/support_level_table.php


- Ilan

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

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


Announcing IronPython 2.6 CTP for .NET 4.0 Beta 1

2009-05-20 Thread Dave Fugate
Hello Python Community,

We're quite pleased to announce the release of IronPython 2.6 CTP for .NET 4.0 
Beta 1.  This is our second preview of IronPython running under the Dynamic 
Language Runtime that is built directly into a .NET 4.0 release!  As before, 
this release allows you to use IronPython objects and types as .NET 4.0 dynamic 
objects from within C# and Visual Basic code.  While this release does share a 
bit in common with the upcoming IronPython 2.6 Beta 1 release (e.g., a number 
of MSI improvements), the core functionality is essentially that of IronPython 
2.6 Alpha 1.  Please also note that IronPython 2.6 CTP for .NET 4.0 Beta 1 
will run only under .NET 4.0 Beta 1.

Here's a small example showing just how powerful the new dynamic feature is for 
taking advantage of dynamic language functionality in statically typed 
languages:
mock.py
import random, math

class Mock(object):
def __getattr__(self, key):
Mock objects of this type will dynamically implement any 
requested member
return random.choice([hello world, math.pi])
 /mock.py

dynamic_demo.cs
using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;

public class dynamic_demo {
static void Main() {
   var ipy = Python.CreateRuntime();
   dynamic mock = ipy.UseFile(mock.py);
   dynamic m = mock.Mock();
   //The Python Mock type dynamically implements any member that is 
requested of it
   
System.Console.WriteLine(m.the_csharp_compiler_cannot_possbily_know_this_member_exists_at_compile_time);
}
}
dynamic_demo.cs


To try out this preview release:

1.   Install some variant of .NET 4.0 Beta 1 or Visual Studio 2010 Beta 1.  
E.g., 
http://www.microsoft.com/downloads/details.aspx?FamilyID=ee2118cc-51cd-46ad-ab17-af6fff7538c9displaylang=en

2.   Install IronPython.msi from 
http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27320

3.   Follow any of the many dynamic walkthroughs online.  
http://blogs.msdn.com/vbteam/archive/2008/12/17/walkthrough-dynamic-programming-in-visual-basic-10-0-and-c-4-0-lisa-feigenbaum.aspx
 would be a good start

Have fun!

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

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


Pydev 1.4.6 Released

2009-05-20 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.4.6 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Auto-import for from __future__ import with_statement will add a
'with' token instead of a with_statement token
* Globals browser improved (only for Eclipse 3.3 onwards, older
versions will have the old interface):
  o Can filter with working sets
  o Can match based on module names. E.g.: django.A would match
all the django classes/methods/attributes starting with 'A'


Release Highlights in Pydev 1.4.6:
--

* Google App Engine: customized setup and management of Google App
Engine projects
* String substitution variables can be used for pythonpath and launch config.
* The interpreter can be referred from a user-editable name
* Submodules shown on import completion (e.g.: from x|-- request
completion here will show xml, xml.dom, xml.etree, etc)
* os.path added to default forced builtins
* Showing better errors when code-completion fails
* Fixed problem finding definition for java class when the constructor
was referenced.
* Fixed recursion error on Python 3.0 grammar
* Jython debugger - local variables are properly updated
* Multiple forced builtins can be added/removed at once
* Python 2.6 grammar: kwarg after unpacking arg list
* Python 3.0 grammar: star expr on for
* Fixed problem on code-completion when file is not in the workspace
(SystemASTManager cannot be cast to ASTManager)
* Not throwing IllegalCharsetNameEx on illegal encoding declaration
anymore (patch by Radim Kubacki)
* __future__ imports are always added/reorganized as the 1st import in
the module
* Code-completion in Jython recognizes that a method get/setName
should be available as a 'name' property.
* Finding 'objects' for django
* Pydev Package Explorer
  o Added filter for the python nodes
  o Showing configuration errors
  o Showing the interpreter info


What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

Aptana
http://aptana.com/python

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


boxee app dev challenge (Python-based API)

2009-05-20 Thread avner (@boxee)
we launched a Python-based API for boxee, and to help promote it we
announced a Dev Challenge with Sony Bravia XBR9 46″ and Drobo with 4TB
of storage as prizes.

you can learn more here http://blog.boxee.tv/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Adding a Par construct to Python?

2009-05-20 Thread Steven D'Aprano
On Tue, 19 May 2009 21:41:08 -0700, Aaron Brady wrote:

 On May 19, 11:20 pm, Paul Rubin http://phr...@nospam.invalid wrote:
 Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
  (4) the caller is responsible for making sure he never shares data
  while looping over it.

  I don't think I've missed any possibilities. You have to pick one of
  those four.

 I wonder if the compiler can check that a given function doesn't change
 any data.  Then:

 @pure
 def f(x):
    return x*sqrt(x) + 3      # does not mutate any data

 @pure
 def g(x): ...                # likewise

 s = parallel_dot_product(parallel_map(f, vec), parallel_map(g,vec))
 
 You can do the basics of this using the 'ast' module.  Just check that
 no nodes in the ast tree are Assign nodes, including augmented assign. 
 Then 'f' is defined as:
 
 f= pure( '''
return x*sqrt(x) + 3  # does not mutate any data
 ''' )
 
 Untested.  


Can you explain how you can tell that there are no side-effects from 
x*sqrt(x)+3 ? What if I have this?

class Funny(object):
def __add__(self, other):
global parrot
parrot += 1
return 5 + other

x = Funny()




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


Re: package with executable

2009-05-20 Thread A. Cavallo
Hi,

 Matplotlib and Numpy, and a command line program. My goal is to create a
 distributable package, that should ideally contain both the gnucal
 package and the command line program.
   * where should the executable module be wrt setup.py and/or the
 package directory in the source tree
   * how should I format the console_scripts entry in setup() to make
 the executable module available to the system PATH after
 installing

With the standard distutils (no need for setuptools) the config.py file might 
look like:


= setup.py =
from distutils.core import setup

version = '0.1'


setup(name='gnucal',
  version=version,
  description=GNUCal is a radiocarbon (14C) calibration program,
  long_description=\
,
  author='Stefano Costa',
  author_email='st...@iosa.it',
  url='http://gnucal.iosa.it/',
  license='GNU GPLv3',
  packages=['gnucal',],
  scripts=['gnucal.py',]
  )

   * how should I call the gnucal package from inside the
 executable script (currently I'm using from gnucal import core
 but it doesn't seem to work)

import gnucal must work. If you're developing from the sources (eg. without 
having the package installed) you need to be in the same dir where the 
gnucal.py is or you need to set PYTHONPATH in order to find the directory 
gnucal (the one containing __init__.py).


 I'm using virtualenv to create testing environments for the install
 process, and my Python is 2.5.4 on Debian Sid.

 Any suggestion is appreciated, particularly if there are some real
 examples to draw from.

At line 101 the statement sys.exit(Please.. should be parser.error(Please..

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


Re: distutils and building an distribution that includes other packages

2009-05-20 Thread Paul Hemans
On May 20, 3:01 pm, Chris Rebert c...@rebertia.com wrote:
  Chris Rebert c...@rebertia.com wrote in message
 news:mailman.426.1242792992.8015.python-l...@python.org...
  On Tue, May 19, 2009 at 8:55 PM, Paul Hemans dar...@nowhere.com wrote:
  Hi,
  I am new to Python, and after a lot of sweat and tears, I have my first
  app.
  Now I need to deploy it to end-users. The application includes the use of
  lxml and sqlAlchemy so I need those to install automatically as part of
  the
  installation process. I really don't want the users having to download
  various modules and install them. Is this facility (to download and
  install
  other packages seamlessly) part of distutils? If so, I have been looking
  around for a simple tutorial on the topic but haven't found anything yet.
  Can anyone point me to some information?

  Since I'm guessing your platform is Windows, you'll probably be
  interested in py2exe -http://www.py2exe.org/

  Cheers,
  Chris
 On Tue, May 19, 2009 at 9:31 PM, Paul Hemans dar...@nowhere.com wrote:
  Hi Chris,
  Yes I do intend to use py2exe for windows installation but I don't
  understand how it will help me distribute lxml and sqlAlchemy as part of the
  install, or am I missing something?

 Granted I haven't used Windows (and thus py2exe) in a while, but last
 I recall the executable it produced was a self-contained Python
 executable containing the main script and all its necessary
 modules/libraries. I think there were some issues getting it to
 include certain finnicky third-party libraries, but once tweaked
 properly it could be coaxed to include them.

 Thus, you don't need to install/distribute the libraries at all;
 they'll be included as part of the generated executable. Then to
 distribute/install your program, you just copy the executable (and
 maybe a DLL or two, again it's been a while).

 Cheers,
 Chris
 --http://blog.rebertia.com- Hide quoted text -

 - Show quoted text -

Ah, I was overcomplicating things (again).
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python mail truncate problem

2009-05-20 Thread Tim Roberts
David ww...@yahoo.com wrote:

I am writing Python script to process e-mails in a user's mail
account. What I want to do is to update that e-mail's Status to 'R'
after processing it, however, the following script truncates old e-
mails even though it updates that e-mail's Status correctly. Anybody
knows how to fix this?

Truncates in what way?  When I tried this, it seemed to work fine.

Note, however, that it is somewhat dangerous to modify an iterator while
you are using it.  (That is, you are setting mbox[key] while doing
mbox.iteritems.)  I might suggest you grab the keys as a list and iterate
through them:

   for key in mbox.keys():
   msg = mbox[key]
   ...
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subversion commit from Python?

2009-05-20 Thread Lawrence D'Oliveiro
In message 5f7f9840-0e17-48fb-acf9-04186fb1b...@r3g2000vbp.googlegroups.com, 
Jack Trades wrote:

 On May 19, 3:53 am, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand 
 wrote:

 Possibly your CGI scripts are running as some user like nobody, which
 doesn't have the right access to the files/directories. Changing APIs
 won't help here.
 
 If that is the case, would setuid be appropriate here?

You mean suexec? Certainly, yes.

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


Re: Subversion commit from Python?

2009-05-20 Thread Lawrence D'Oliveiro
In message 77fv7jf1h44c...@mid.uni-berlin.de, Diez B. Roggisch wrote:

 I have had many troubles with SVN + permissions.

I create a custom captive user to own write access to the repository, with 
access only to keys belonging to authorized users via svn+ssh. Problem 
solved.

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


Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Peter Otten
Mitchell L Model wrote:

 Suppose I have a simple query in sqlite3 in a function:
 
 def lookupxy(x, y):
 conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 = ?,
  (x, y))
 
 However, COL2 might be NULL. I can't figure out a value for y that would
 retrieve rows for which COL2 is NULL. It seems to me that I have to
 perform an awkward test to determine whether to execute a query with one
 question mark or two.
 
 def lookupxy(x, y):
 if y:
 conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 =
 ?,
  (x, y))
 else:
 conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 IS
 NULL,
  (x,))
 
 The more question marks involved the more complicated this would get,
 especially if question marks in the middle of several would sometimes need
 to be NULL. I hope I'm missing something and that someone can tell me what
 it is.

You could create a custom function

def equals(a, b):
return a == b

conn.create_function(equals, 2, equals)

cursor.execute(select * from table where equals(col1, ?) and ..., (x,...))

Or you do some gymnastics in Python:

class Expr(object):
def __init__(self, dict):
self.dict = dict
def __getitem__(self, key):
value = self.dict[key]
if value is None:
return (%s is null) % key
return (%s = :%s) % (key, key)

def lookup(col1, col2):
lookup = locals()
sql = SELECT * FROM table WHERE %(col1)s AND %(col2)s % Expr(lookup)
return conn.execute(sql, lookup)

I think these are both more readable than

... where case when :col1 is null then (col1 is null) else (col1 = :col1) end 
...

Peter



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


Re: How can i use Spread Sheet as Data Store

2009-05-20 Thread Kalyan Chakravarthy
Thanks Alex
   Then tell me how can I solve this issue.

Thanks in advance

Regards
Kalyan

On Wed, May 20, 2009 at 8:11 AM, alex23 wuwe...@gmail.com wrote:

 On May 19, 11:57 pm, D'Arcy J.M. Cain da...@druid.net wrote:
  I hear you but I'm not so sure that that is an absolute.  There are
  many applications that allow you to have your password emailed to you.
  For something with low risk that's perfectly acceptable.

 Having -any- password stored in plaintext is unacceptable. I'm pretty
 sure I'm not the only person who uses a simple algorithm to generate
 passwords based on context. If you're running a site and you're not
 going to bother to secure my credentials, I'd hope you'd at least
 mention that at sign up so I could adjust my behaviour as appropriate.
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Regards
Kalyan
Mobile no: +91 9985351220
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHONPATH on Windows XP module load problem

2009-05-20 Thread Andreas Otto
Hi,

  I try to use distutils and setup.py to create an C extension

  Now a list of problems:

  1. I'm using automake, autoconf to setup the build-environment
for example CPPFLAGS

- how can I transport the CPPFLAGS on the commandline
to setup.py 

I can not use the define_macros argument in the setup.py
script

  2. the following shared library is created:

build/lib.linux-x86_64-3.0/pymsgque.so

- in my tool a test environment is included this mean
after a build but before install a test is
done. this mean that the library have to be found
and used by the test-environment.

- the problem is that the directory name
build/lib.linux-x86_64-3.0/
is system-depend

- question: how I get an unique system independent name
or just in general how I solve this kind of problem

  3. why is no .pyd file created ?

- pyd is the extension name supported 


mfg

  Andreas Otto


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


Re: optparse options

2009-05-20 Thread Mike Kazantsev
Ben Finney wrote:
 icarus rsa...@gmail.com writes:
 
  parser = optparse.OptionParser(usage=%prog [-p dir] [--part=dir] ,
 version=%prog 1.0)

  parser.add_option( -p, --part, dest=directory,
help=process target directory, metavar=dir)
  (options, args) = parser.parse_args()

...

  if len(args) != 1:
  parser.error(No options specified)
 
 The message is confusing, since it doesn't match the condition; it would
 be correct to say “Did not specify exactly one non-option argument”.
 
 In this case, it looks like you don't want to check this at all, and
 should instead operate on the basis of the options only.

I also wanted to note that it looks quite illogical and
counter-intuitive to create required options, since by definition they
should be optional.
Try using arguments instead, with some type-switching flags, if
necessary - it should make CLI more consistent and save some typing by
omitting otherwise always-required option argument (--part).

-- 
Mike Kazantsev // fraggod.net



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a Par construct to Python?

2009-05-20 Thread jeremy
On 20 May, 03:43, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Tue, 19 May 2009 03:57:43 -0700, jeremy wrote:
  you want it so simple to use that amateurs can mechanically replace
  'for' with 'par' in their code and everything will Just Work, no effort
  or thought required.

  Yes I do want the par construction to be simple, but of course you can't
  just replace a for loop with a par loop in the general case.

 But that's exactly what you said you wanted people to be able to do:

 with my suggestion they could potentially get a massive speed up just by
 changing 'for' to 'par' or 'map' to 'pmap'.

 I am finding this conversation difficult because it seems to me you don't
 have a consistent set of requirements.

  This issue
  arises when people use OpenMP: you can take a correct piece of code, add
  a comment to indicate that a loop is 'parallel', and if you get it wrong
  the code with no longer work correctly.

 How will 'par' be any different? It won't magically turn code with
 deadlocks into bug-free code.

  With my 'par' construct the
  programmer's intention is made explicit in the code, rather than by a
  compiler directive and so I think that is clearer than OpenMP.

 A compiler directive is just as clear about the programmer's intention as
 a keyword. Possibly even more so.

 #$ PARALLEL-LOOP
 for x in seq:
     do(x)

 Seems pretty obvious to me. (Not that I'm suggesting compiler directives
 is a good solution to this problem.)

  As I wrote before, concurrency is one of the hardest things for
  professional programmers to grasp. For 'amateur' programmers we need to
  make it as simple as possible,

 The problem is that as simple as possible is Not Very Simple. There's
 no getting around the fact that concurrency is inherently complex. In
 some special cases, you can keep it simple, e.g. parallel-map with a
 function that has no side-effects. But in the general case, no, you can't
 avoid dealing with the complexity, at least a little bit.

  and I think that a parallel loop
  construction and the dangers that lurk within would be reasonably
  straightforward to explain: there are no locks to worry about, no
  message passing.

 It's *already* easy to explain. And having explained it, you still need
 to do something about it. You can't just say Oh well, I've had all the
 pitfalls explained to me, so now I don't have to actually do anything
 about avoiding those pitfalls. You still need to actually avoid them.
 For example, you can choose one of four tactics:

 (1) the loop construct deals with locking;

 (2) the caller deals with locking;

 (3) nobody deals with locking, therefore the code is buggy and risks
 deadlocks; or

 (4) the caller is responsible for making sure he never shares data while
 looping over it.

 I don't think I've missed any possibilities. You have to pick one of
 those four.

  The only advanced concept is the 'sync' keyword, which
  would be used to rendezvous all the threads. That would only be used to
  speed up certain codes in order to avoid having to repeatedly shut down
  and start up gangs of threads.

 So now you want a second keyword as well.

 --
 Steven

Hi Steven,

You wrote:

 I am finding this conversation difficult because it seems to me you don't 
 have a consistent set of requirements.

I think that my position has actually been consistent throughout this
discussion about what I would like to achieve. However I have learned
more about the inner workings of python than I knew before which have
made it clear that it would be difficult to implement (in CPython at
least). And also I never intended to present this as a fait accompli -
the intention was to start a debate as we have been doing. You also
wrote

 So now you want a second keyword as well

I actually described the 'sync' keyword in my second email before
anybody else contributed.

I *do* actually know a bit about concurrency and would never imply
that *any* for loop could be converted to a parallel one. The
intention of my remark with my suggestion they could potentially get
a massive speed up just by changing 'for' to 'par' or 'map' to
'pmap'. is that it could be applied in the particular circumstances
where there are no dependencies between different iterations of the
loop.

Regarding your implementation strategies, mine would be related to
this one:

 (4) the caller is responsible for making sure he never shares data while
 looping over it.

However in my world there is no problem with threads sharing data as
long as they do not change the values. So the actual rule would be
something like:

5. The caller is responsible for making sure that one iteration of the
parallel loop never tries to write to a variable that another
iteration may read, unless separated by a 'sync' event.

This shows why the sync event is needed - to avoid  race conditions on
shared variables. It is borrowed from the BSP paradigm - although that
is a distibuted memory approach. Without the sync clause, 

Yet another question about class property.

2009-05-20 Thread Jim Qiu
Hi everyone,

Following is the code i am reading, i don't see anywhere the declaration of
Message.root object,
Where is it from?

#bots-modules
import bots.botslib as botslib
import bots.node as node
from bots.botsconfig import *


class Message(object):
''' abstract class; represents a edi message.
is subclassed as outmessage or inmessage object.
'''
def __init__(self):
self.recordnumber=0#segment counter. Is not used for
UNT of SE record; some editypes want sequential recordnumbering

@staticmethod
def display(records):
'''for debugging lexed records.'''
for record in records:
t = 0
for veld in record:
if t==0:
print '%s(Record-id)'%(veld[VALUE])
else:
if veld[SFIELD]:
print '%s(sub)'%(veld[VALUE])
else:
print '%s(veld)'%(veld[VALUE])
t += 1

def get(self,*mpaths):
''' query tree (self.root) with mpath; get value (string); get None
if not found.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.get(*mpaths)

def getnozero(self,*mpaths):
''' like get, returns None is value is zero (0) or not numeric.
Is sometimes usefull in mapping.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.getnozero(*mpaths)

def getindicator(self,ind,*mpaths):
''' like get, returns None is value is zero (0) or not numeric.
Is sometimes usefull in mapping.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.getindicator(ind,*mpaths)

def getcount(self):
''' count number of nodes in self.root. Number of nodes is number of
records.'''
return self.root.getcount()

def getcountoccurrences(self,*mpaths):
''' count number of nodes in self.root. Number of nodes is number of
records.'''
count = 0
for value in self.getloop(*mpaths):
count += 1
return count

def getcountsum(self,*mpaths):
''' return the sum for all values found in mpath. Eg total number of
ordered quantities.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.getcountsum(*mpaths)

def getloop(self,*mpaths):
''' query tree with mpath; generates all the nodes. Is typically
used as: for record in inn.get(mpath):
'''
if self.root.record:#self.root is a real root
for terug in self.root.getloop(*mpaths): #search recursive for
rest of mpaths
yield terug
else:   #self.root is dummy root
for childnode in self.root.children:
for terug in childnode.getloop(*mpaths): #search recursive
for rest of mpaths
yield terug

def put(self,*mpaths):
if self.root.record is None and self.root.children:
raise botslib.MpathRootError('put(%s): root of outgoing
message is empty; use out.putloop'%(str(mpaths)))
return self.root.put(*mpaths)

def putloop(self,*mpaths):
if not self.root.record:#no input yet, and start with a
putloop(): dummy root
if len(mpaths) == 1:
self.root.append(node.Node(mpaths[0]))
return self.root.children[-1]
else: #TODO: what if self.root.record is None and len(mpaths) 
1?
raise botslib.MpathRootError('putloop(%s): mpath too
long???'%(str(mpaths)))
return self.root.putloop(*mpaths)

def sort(self,*mpaths):
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of message is
empty; either split messages or use inn.getloop'%(str(mpaths)))
self.root.sort(*mpaths)

def normalisetree(self,node):
''' The node tree is check, sorted, fields are formated etc.
Always use this method before writing output.
'''
#~ node.display()
#~ print 'normalisetree'
self._checktree(node,self.defmessage.structure[0])
self._canonicaltree(node,self.defmessage.structure[0])

def _checktree(self,tree,structure):
''' checks tree with table:
-   all records should be in table at the right place in
hierarchy
-   for each record, all fields should be in grammar
This function checks the root 

Re: PYTHONPATH on Windows XP module load problem

2009-05-20 Thread Andreas Otto
Hi,

  after we know how your bathroom looks like ...

  I have done additional research.

1. setup a setup.py script
2. compiled the extension
3. copy the extension to the test directory
- cp ../pymsgque/build/lib.win32-3.0-pydebug/pymsgque.pyd .
4. start the test

$ python_d.exe ./server.py
Traceback (most recent call last):
  File ./server.py, line 13, in module
import pymsgque
ImportError: No module named pymsgque
[31909 refs]

- same as before

Question:

- is the module was not found or
could a found module not be loaded

mfg

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


SpellChecker

2009-05-20 Thread abosalim
I used this code.It works fine,but on word not whole text.I want to
extend this code to correct
text file not only a word,but i don't know.If you have any help,please
inform me.

This is the code:

import re, collections

def words(text): return re.findall('[a-z]+', text.lower())

def train(features):
model = collections.defaultdict(lambda: 1)
for f in features:
model[f] += 1
return model

NWORDS = train(words(file('big.txt').read()))

alphabet = 'abcdefghijklmnopqrstuvwxyz'

def edits1(word):
n = len(word)
return set([word[0:i]+word[i+1:] for i in range(n)]
+ # deletion
   [word[0:i]+word[i+1]+word[i]+word[i+2:] for i in range
(n-1)] + # transposition
   [word[0:i]+c+word[i+1:] for i in range(n) for c in
alphabet] + # alteration
   [word[0:i]+c+word[i:] for i in range(n+1) for c in
alphabet])  # insertion

def known_edits2(word):
return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in
NWORDS)

def known(words): return set(w for w in words if w in NWORDS)

def correct(word):
candidates = known([word]) or known(edits1(word)) or known_edits2
(word) or [word]
return max(candidates, key=lambda w: NWORDS[w])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another question about class property.

2009-05-20 Thread Mike Kazantsev
Jim Qiu wrote:
 Hi everyone,
 
 Following is the code i am reading, i don't see anywhere the declaration of
 Message.root object,
 Where is it from?
...

Prehaps it gets assigned by the parent itself?
Like this:

  def spawn_child(self):
child = Message()
child.root = self

-- 
Mike Kazantsev // fraggod.net



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conceptual flaw in pxdom?

2009-05-20 Thread Diez B. Roggisch
Paul Boddie wrote:

 On 19 Mai, 18:16, Diez B. Roggisch de...@nospam.web.de wrote:

 Sorry to say so, but that's nonsense. DOM is not complicated because it
 contains anything superior - the reason (if any) is that it is formulated
 as language-agnostic as possible, with the unfortunate result it is
 rather clumsy to use in all languages.
 
 Although I presume that people really mean the core standards when
 they talk about the DOM, not all the other ones related to those
 core standards, the API is not to everyone's taste because, amongst
 other things, it uses functions and methods when some people would
 rather use properties (which actually appear in various places in the
 standards, so it isn't as if the W3C haven't heard of such things),
 and for lots of other subjective reasons: some I can agree with, some
 I put at the same level as a lot of the API-posturing in numerous
 domains where Python code gets written, where such code jostles above
 all other concerns for the coveted Pythonic label.
 
 However, when people are actually choosing to use DOM-related
 technologies, and when those technologies do not necessarily have
 equivalents in whatever other technology stack that could be
 suggested, can we not just take it as read that they actually know
 that the DOM isn't very nice (or that other people don't think that
 it's very nice) and that there are alternatives to the core stuff
 (especially when the inquirer has actually indicated his familiarity
 with those alternatives) and that reminding everyone for the nth time
 about how bad the DOM is (for whatever tangential purpose only
 partially related to the topic under discussion) adds very little if
 anything in the way of advice? It's like someone saying that they're
 going to fly the Atlantic in a 747 only to be told that they should
 drive a Lexus because Boeing make terrible cars.
 
 Feel free to replace DOM in the above with whatever else fits,
 because this kind of thing comes up all the time.

You could have wrote that same reply when the OP stated that 


It [DOM] might be more
complicated, but that's probably because lots of very smart people
thought about it very carefully and it couldn't be made any simpler.


Which is another way of saying I know X, but Y is better. 

Also, not trying to convince people that there are better alternatives to
what and how they do something (admittedly, better is subjective, thus
ensues discussion), or gathering arguments on why they do believe their way
is preferable is the very essence of fora like this - if you'd really want
that to go away, we're down to answering the notorious
mutable-default-argument-question.

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


monitoring friendly applications

2009-05-20 Thread Imbaud Pierre
I have A LOT of batch applications to monitor, on linux machines, mostly 
written in python.

I have to know:
- which are active, at a given moment?
- when did the last run occur? How long did it last?
- for some daemons: are they stuck? generally, waiting for i/o, or lost 
in some C call.


I could do this (I partly did, btw) thru external processes tools. But 
most processes are python programs, making slight changes is not a 
problem. Thats why I think a python library could help me here; let us 
call it mfa (for monitor friendly application); then one call to 
mfa.in() at start (or at import?), mfa.out() at exit (maybe even on 
exception?), and possibly mfa.loop(), for loop managed daemons. the 
library would open a pipe, or a flow (to a file, a centralizing process, 
a database, a log), and every call make a dated entry. Ideally, the 
application should not be aware of the implementation, especially the 
repository being a file or a db.
Another aspect of process management can be endorsed by the library: 
sometimes only one instance of the process should be active, then 
withdraw if already running.
Not a lot of code to write, but careful design, to keep things simple, 
reliable, only add a low overhead, etc.
By any chance, does something like this exist? Would someone be 
interested with this development?

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


Re: SpellChecker

2009-05-20 Thread Mike Kazantsev
abosalim wrote:
 I used this code.It works fine,but on word not whole text.I want to
 extend this code to correct
 text file not only a word,but i don't know.If you have any help,please
 inform me.
...
 def correct(word):
 candidates = known([word]) or known(edits1(word)) or known_edits2
 (word) or [word]
 return max(candidates, key=lambda w: NWORDS[w])

Here I assume that word is any string consisting of letters, feel free
to add your own check in place of str.isalpha, like word length or case.
Note that simple ops like concatenation work much faster with buffers
than str / unicode.

  text = 'some text to correct (anything, really)'
  result = buffer('')

  word, c = buffer(''), ''
  for c in text:
if c.isalpha(): word += c
else:
  if word:
result += correct(word)
word = buffer('')
  result += c

-- 
Mike Kazantsev // fraggod.net



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SpellChecker

2009-05-20 Thread Peter Otten
abosalim wrote:

 I used this code.It works fine,but on word not whole text.I want to
 extend this code to correct
 text file not only a word,but i don't know.If you have any help,please
 inform me.

import re
import sys

def correct(word, _lookup={teh: the}):

Replace with Norvig's implementation found at

http://norvig.com/spell-correct.html

return _lookup.get(word.lower(), word)

def correct_word(word):
corrected = correct(word)
if corrected != word:
if word.istitle():
corrected = corrected.title()
if word.isupper():
corrected = corrected.upper()
print  sys.stderr, correcting, word, --, corrected
return corrected

def sub_word(match):
return correct_word(match.group())

def correct_text(text):
return re.compile([a-z]+, re.I).sub(sub_word, text)

if __name__ == __main__:
text = Teh faster teh better TEH BIGGER
print original:, text
print corrected:, correct_text(text)


Peter

PS: Don't you get bored if you have all your code written for you?


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


Re: Adding a Par construct to Python?

2009-05-20 Thread Paul Boddie
On 20 Mai, 07:57, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:

 Can you explain how you can tell that there are no side-effects from
 x*sqrt(x)+3 ? What if I have this?

 class Funny(object):
     def __add__(self, other):
         global parrot
         parrot += 1
         return 5 + other

 x = Funny()

Yes, in general you need whole-program analysis with Python to know if
there are any side-effects or not. That said, with a process forking
mechanism where modified globals are not global beyond each process,
you should be able to guard against side-effects more effectively.

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


Re: Yet another question about class property.

2009-05-20 Thread Dave Angel

Jim Qiu wrote:

Hi everyone,

Following is the code i am reading, i don't see anywhere the declaration of
Message.root object,
Where is it from?

#bots-modules
import bots.botslib as botslib
import bots.node as node
from bots.botsconfig import *


class Message(object):
''' abstract class; represents a edi message.
is subclassed as outmessage or inmessage object.
'''
def __init__(self):
self.recordnumber=0#segment counter. Is not used for
UNT of SE record; some editypes want sequential recordnumbering

@staticmethod
def display(records):
'''for debugging lexed records.'''
for record in records:
t = 0
for veld in record:
if t==0:
print '%s(Record-id)'%(veld[VALUE])
else:
if veld[SFIELD]:
print '%s(sub)'%(veld[VALUE])
else:
print '%s(veld)'%(veld[VALUE])
t += 1

def get(self,*mpaths):
''' query tree (self.root) with mpath; get value (string); get None
if not found.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.get(*mpaths)

def getnozero(self,*mpaths):
''' like get, returns None is value is zero (0) or not numeric.
Is sometimes usefull in mapping.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.getnozero(*mpaths)

def getindicator(self,ind,*mpaths):
''' like get, returns None is value is zero (0) or not numeric.
Is sometimes usefull in mapping.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.getindicator(ind,*mpaths)

def getcount(self):
''' count number of nodes in self.root. Number of nodes is number of
records.'''
return self.root.getcount()

def getcountoccurrences(self,*mpaths):
''' count number of nodes in self.root. Number of nodes is number of
records.'''
count = 0
for value in self.getloop(*mpaths):
count += 1
return count

def getcountsum(self,*mpaths):
''' return the sum for all values found in mpath. Eg total number of
ordered quantities.'''
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of incoming
message is empty; either split messages or use inn.getloop'%(str(mpaths)))
return self.root.getcountsum(*mpaths)

def getloop(self,*mpaths):
''' query tree with mpath; generates all the nodes. Is typically
used as: for record in inn.get(mpath):
'''
if self.root.record:#self.root is a real root
for terug in self.root.getloop(*mpaths): #search recursive for
rest of mpaths
yield terug
else:   #self.root is dummy root
for childnode in self.root.children:
for terug in childnode.getloop(*mpaths): #search recursive
for rest of mpaths
yield terug

def put(self,*mpaths):
if self.root.record is None and self.root.children:
raise botslib.MpathRootError('put(%s): root of outgoing
message is empty; use out.putloop'%(str(mpaths)))
return self.root.put(*mpaths)

def putloop(self,*mpaths):
if not self.root.record:#no input yet, and start with a
putloop(): dummy root
if len(mpaths) == 1:
self.root.append(node.Node(mpaths[0]))
return self.root.children[-1]
else: #TODO: what if self.root.record is None and len(mpaths) 
1?
raise botslib.MpathRootError('putloop(%s): mpath too
long???'%(str(mpaths)))
return self.root.putloop(*mpaths)

def sort(self,*mpaths):
if self.root.record is None:
raise botslib.MpathRootError('get(%s): root of message is
empty; either split messages or use inn.getloop'%(str(mpaths)))
self.root.sort(*mpaths)

def normalisetree(self,node):
''' The node tree is check, sorted, fields are formated etc.
Always use this method before writing output.
'''
#~ node.display()
#~ print 'normalisetree'
self._checktree(node,self.defmessage.structure[0])
self._canonicaltree(node,self.defmessage.structure[0])

def _checktree(self,tree,structure):
''' checks tree with table:
-   all records should be in table at the right place in
hierarchy
-   for each record, all fields should be in grammar
This function 

Re: finding repeated data sequences in a column

2009-05-20 Thread bearophileHUGS
yadin, understanding what you want is probably 10 times harder than
writing down the code :-)

 I have a a table, from where I can extract a column.

You can extract it? Or do you want to extract it? Or do you want to
process it? Etc.


 I wanna go down trough that column made of numbers
 examine undetermined chunks of data and see or detect if that sequence
 of chunk
 of data has been repeated before

What do you mean by undetermined? What kind of data? Where is this
data? How is this chunk shaped? Are you talking about a string?


 and if it has been repeated detect it by giving it a name in an
 adjacent column.

What kind of name? So you just need 2 names, like N and S for New and
Seen?
You can use a built-in set data structure to know if you have already
seen some data, while you scan the records.


 Imagine someting like this but made of 1800 numbers...

How are such 1800 disposed? Do you mean 1800 columns of 32 bit
numbers?


 how can I build up column 3(category)

What does A, B and C mean?

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: identifying live hosts on a network

2009-05-20 Thread Philipp Hagemeister
We acknowledge your problems with a network script idenifying live hosts
on your network.

Seriously, you have to tell us a little bit more so that we can help
you. How about you actually post the script, and actually post the
trouble (What exactly do you expect? What exactly do you see? What other
steps have you tried?)

Philipp

hunteroakes...@gmail.com wrote:
 HI
 I am new to python and am having trouble coming up with a script that
 idenifies all the live hosts on my network.
 thanks Hunter





signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


finding repeated data sequences in a column

2009-05-20 Thread yadin
Good day everyone!
I have a a table, from where I can extract a column.
I wanna go down trough that column made of numbers
examine undetermined chunks of data and see or detect if that sequence
of chunk
of data has been repeated before
and if it has been repeated detect it by giving it a name in an
adjacent column.
Imagine someting like this but made of 1800 numbers... how can I build
up column 3(category)

Itemprice Category
400 128706  A
400 128707  A
400 128708  A
101 100 C
101 12  C
500 128706  A
500 128707  A
500 128708  A
500 128709  B
120 128706  A
120 128707  A
120 128708  A
120 100 C
120 12  C
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: P2P text chat engine

2009-05-20 Thread Kirill
On 7 май, 21:23, Diez B. Roggisch de...@nospam.web.de wrote:
 Navanjo schrieb:

  If you have the source code of a p2p text chat engine please send to me

 I found that  a pot of gold under my bed. Care to give me your address
 so that I can send it to you?

 SCNR,
 Diez

Hello, can you sent it to me ?
ave...@gmail.com
Many thanks!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a better way to chose a slice of a list?

2009-05-20 Thread Piet van Oostrum
 walterbyrd walterb...@iname.com (w) wrote:

w On May 8, 5:55 pm, John Yeung gallium.arsen...@gmail.com wrote:
 On May 8, 3:03 pm,walterbyrdwalterb...@iname.com wrote:
 
  This works, but it seems like there should be a better way.
 
  --
  week = ['sun','mon','tue','wed','thu','fri','sat']
  for day in week[week.index('tue'):week.index('fri')]:
     print day
  ---
 
 I think you should provide much more information, primarily why you
 want to do this.  What is the larger goal you are trying to achieve?

w I am just looking for a less verbose, more elegant, way to print a
w slice of a list. What is hard to understand about that? I am not sure
w how enumerated types help.

You didn't say that in the OP.

But you can extend the list type to accept slices with strings in them.
The language spec says they should be ints but apparently this is not
enforced. Of course this makes it vulnerable for future misbehaviour.

class KeyList(list):
def __getitem__(self, indx):
if isinstance(indx, slice):
start = indx.start
stop = indx.stop
# add support for step if you want
if not isinstance(start, int):
start = self.index(start)
if not isinstance(stop, int):
stop = self.index(stop)
return list.__getitem__(self, slice(start,stop))
return list.__getitem__(self, indx)

week = KeyList(['sun','mon','tue','wed','thu','fri','sat'])
for day in week['tue':'fri']:
   print day

tue
wed
thu

Note that 'fri' is not included according to standard Python conventions
about the end of a slice. Change the code if you are not happy with it
and you don't mind getting inconsistent semantics.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I make pprint do this

2009-05-20 Thread jcervidae
I cannot get pprint to format output how I would like. pydb does. I
tried grepping the source but still couldn't grok it. Here:

(Pydb) a = range(1,100)
(Pydb) pp a
[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20
 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40
 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60
 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79...]

It puts multiple elements on the same line. I can't work out how to
make it do that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get Form values in Python code and Send Email

2009-05-20 Thread James Matthews
Why don't you use Django? If you get the form information from Django you
can send an email using the send_mail (or even if you don't you can still
import the function.



On Wed, May 20, 2009 at 8:52 AM, Kalyan Chakravarthy 
kalyanchakravar...@hyit.com wrote:

 Hi All,

 I have one doubt, I have feedback form (HTML Page) in one website user
 enters all the details and after submitting the page, in back end Python
 class i want to get all those data and send to one email id.

 for this please any one can guide me how to do it in  Python( how to get
 HTML form data in Python and send those data as an Email) and Google Apps

 Thanks in advance

 --
 Regards
 Kalyan


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




-- 
http://www.astorandblack.com
-- 
http://mail.python.org/mailman/listinfo/python-list


White NaNs with pcolor (matplotlib)

2009-05-20 Thread route6
Hi,

I am trying to display the NaNs in white color when I plot a data map
using pcolor with matplotlib. Does anyone know how to do that? By
default the NaNs are displayed in the color corresponding to the
lowest value in the colorbar.

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


Re: How to get Form values in Python code and Send Email

2009-05-20 Thread Kalyan Chakravarthy
Hi
Now i can able to get the form details in to python code,

can any one tell me the format to send form values to one Emil id   ...  for
this  I required SMTP set up?

Thanks in advance

Regards
Kalyan


On Wed, May 20, 2009 at 5:06 PM, James Matthews nytrok...@gmail.com wrote:

 Why don't you use Django? If you get the form information from Django you
 can send an email using the send_mail (or even if you don't you can still
 import the function.



 On Wed, May 20, 2009 at 8:52 AM, Kalyan Chakravarthy 
 kalyanchakravar...@hyit.com wrote:

 Hi All,

 I have one doubt, I have feedback form (HTML Page) in one website user
 enters all the details and after submitting the page, in back end Python
 class i want to get all those data and send to one email id.

 for this please any one can guide me how to do it in  Python( how to get
 HTML form data in Python and send those data as an Email) and Google Apps

 Thanks in advance

 --
 Regards
 Kalyan


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




 --
 http://www.astorandblack.com




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




-- 
Regards
Kalyan
Mobile no: +91 9985351220
-- 
http://mail.python.org/mailman/listinfo/python-list


Problems with import hooks and encoding

2009-05-20 Thread Vinay Sajip
The simple program

#--
 def main():
 print repr(u'\u2029'.encode('utf-8'))

 if __name__ == __main__:
 main()
#--

works as expected when run from the command-line, but fails when
converted to an executable using PyInstaller. (For example, if the
executable is created on a Ubuntu Jaunty system but then run on a
Ubuntu Hardy system.) Digging into why this happens leads to the
observation that Py_Initialize calls _PyUnicode_Init, which in turn
causes encodings to be imported via the _codecs module (codecs.c).
However, this appears to happen before the import hook machinery is
set up. Is there a way of intercepting the importing of encodings so
that a freeze processor like PyInstaller's launcher can redirect the
import to the package bundled with the executable, rather than any
package provided with a host-installed version of Python?

Regards,

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


How to Spawn a process with P_NOWAIT and pass it some data ?

2009-05-20 Thread Barak, Ron
Hi,

This is my first try at IPC in Python, and I would like to ask your help with 
the following problem:

I would like to spawn a process with P_NOWAIT, and pass some data to the child 
process.

I created two scripts to try IPC (in a blocking way):

$ cat subprocess_sender.py
#!/usr/bin/env python

import subprocess

proc = subprocess.Popen([python, -u, subprocess_receiver.py], 
stdin=subprocess.PIPE, shell=True)

proc.communicate(input=this is sent from subprocess_sender.py)[0]
proc.stdin.close()
and

$ cat subprocess_receiver.py
#!/usr/bin/env python

import sys

print sys.stdin.readline()
These scripts intercommunicate nicely:

$ python -u  subprocess_sender.py
this is sent from subprocess_sender.py
The example in the documentation is:
18.1.3.4. Replacing the os.spawn 
family¶http://docs.python.org/library/subprocess.html#replacing-the-os-spawn-family

P_NOWAIT example:

pid = os.spawnlp(os.P_NOWAIT, /bin/mycmd, mycmd, myarg)
==
pid = Popen([/bin/mycmd, myarg]).pid

But, when I try it in my script:

$ cat subprocess_sender.py
#!/usr/bin/env python

import subprocess

proc = subprocess.Popen([python, -u, subprocess_receiver.py], 
stdin=subprocess.PIPE, shell=True).pid

proc.communicate(input=this is sent from subprocess_sender.py)[0]
proc.stdin.close()
proc is now changed from a subprocess.Popen object to an int, namely:

$ python -u  subprocess_sender.py
Traceback (most recent call last):
  File subprocess_sender.py, line 7, in module
proc.communicate(input=this is sent from subprocess_sender.py)[0]
AttributeError: 'int' object has no attribute 'communicate'
Can anyone suggest what is the correct way to implement P_NOWAIT and still be 
able to communicate with the child process ?
(Or, is there a way to create a subprocess.Popen object from what I assume is 
the process handle integer ?)

Thanks,
Ron.

The numbering of the scripts' lines:

$ cat -n subprocess_sender.py
 1  #!/usr/bin/env python
 2
 3  import subprocess
 4
 5  proc = subprocess.Popen([python, -u, subprocess_receiver.py], 
stdin=subprocess.PIPE, shell=True).pid
 6
 7  proc.communicate(input=this is sent from subprocess_sender.py)[0]
 8  proc.stdin.close()

$ cat -n subprocess_receiver.py
 1  #!/usr/bin/env python
 2
 3  import sys
 4
 5  print sys.stdin.readline()

inline: attcb52c.jpginline: attcb54c.jpg-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Jean-Michel Pichavant
I fall into the same issue when using postgres. Your main concern is 
that NULL = NULL will return False. Could seems strange but it has much 
advantages sometimes, however this is not the purpose.
I found your solution quite acceptable. Just replace 'if y:' by 'if y is 
None:', add a comment to point that #NULL  NULL to help any reader 
that is not familiar with db and you got a perfectly readable code.


Of course if you have more complex queries to build you'll have to think 
about an elegant way to manage NULL values. I personally iterate trough 
all my COLs and add a 'COL# = ?' if the value queried is not None. It 
works, it's readable, it's simple, it's python :o)


JM


Mitchell L Model wrote:

Suppose I have a simple query in sqlite3 in a function:

def lookupxy(x, y):
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 = ?,
 (x, y))

However, COL2 might be NULL. I can't figure out a value for y that would 
retrieve rows for which COL2 is NULL. It seems to me that I have to perform an 
awkward test to determine whether to execute a query with one question mark or 
two.

def lookupxy(x, y):
if y:
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 = ?,
 (x, y))
else:
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 IS NULL,
 (x,))

The more question marks involved the more complicated this would get, 
especially if question marks in the middle of several would sometimes need to 
be NULL. I hope I'm missing something and that someone can tell me what it is.
  


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


Re: Adding a Par construct to Python?

2009-05-20 Thread Iain King
On May 19, 10:24 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Mon, 18 May 2009 02:27:06 -0700, jeremy wrote:
  Let me clarify what I think par, pmap, pfilter and preduce would mean
  and how they would be implemented.

 [...]

 Just for fun, I've implemented a parallel-map function, and done a couple
 of tests. Comments, criticism and improvements welcome!

 import threading
 import Queue
 import random
 import time

 def f(arg):  # Simulate a slow function.
     time.sleep(0.5)
     return 3*arg-2

 class PMapThread(threading.Thread):
     def __init__(self, clients):
         super(PMapThread, self).__init__()
         self._clients = clients
     def start(self):
         super(PMapThread, self).start()
     def run(self):
         while True:
             try:
                 data = self._clients.get_nowait()
             except Queue.Empty:
                 break
             target, where, func, arg = data
             result = func(arg)
             target[where] = result

 class VerbosePMapThread(threading.Thread):
     def __init__(self, clients):
         super(VerbosePMapThread, self).__init__()
         print Thread %s created at %s % (self.getName(), time.ctime())
     def start(self):
         super(VerbosePMapThread, self).start()
         print Thread %s starting at %s % (self.getName(), time.ctime())
     def run(self):
         super(VerbosePMapThread, self).run()
         print Thread %s finished at %s % (self.getName(), time.ctime())

 def pmap(func, seq, verbose=False, numthreads=4):
     size = len(seq)
     results = [None]*size
     if verbose:
         print Initiating threads
         thread = VerbosePMapThread
     else:
         thread = PMapThread
     datapool = Queue.Queue(size)
     for i in xrange(size):
         datapool.put( (results, i, f, seq[i]) )
     threads = [PMapThread(datapool) for i in xrange(numthreads)]
     if verbose:
         print All threads created.
     for t in threads:
         t.start()
     # Block until all threads are done.
     while any([t.isAlive() for t in threads]):
         if verbose:
             time.sleep(0.25)
             print results
     return results

 And here's the timing results:

  from timeit import Timer
  setup = from __main__ import pmap, f; data = range(50)
  min(Timer('map(f, data)', setup).repeat(repeat=5, number=3))
 74.999755859375
  min(Timer('pmap(f, data)', setup).repeat(repeat=5, number=3))

 20.490942001342773

 --
 Steven

I was going to write something like this, but you've beat me to it :)
Slightly different though; rather than have pmap collate everything
together then return it, have it yield results as and when it gets
them and stop iteration when it's done, and rename it to par to keep
the OP happy and you should get something like what he initially
requests (I think):

total = 0
for score in par(f, data):
total += score


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


Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Jean-Michel Pichavant

Erratum:

please read 'if y is *not* None:'. (think that if y = 0, you won't 
execute the proper code block with 'if y:').


JM

Jean-Michel Pichavant wrote:
I fall into the same issue when using postgres. Your main concern is 
that NULL = NULL will return False. Could seems strange but it has 
much advantages sometimes, however this is not the purpose.
I found your solution quite acceptable. Just replace 'if y:' by 'if y 
is None:', add a comment to point that #NULL  NULL to help any 
reader that is not familiar with db and you got a perfectly readable 
code.


Of course if you have more complex queries to build you'll have to 
think about an elegant way to manage NULL values. I personally iterate 
trough all my COLs and add a 'COL# = ?' if the value queried is not 
None. It works, it's readable, it's simple, it's python :o)


JM


Mitchell L Model wrote:

Suppose I have a simple query in sqlite3 in a function:

def lookupxy(x, y):
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 = ?,
 (x, y))

However, COL2 might be NULL. I can't figure out a value for y that 
would retrieve rows for which COL2 is NULL. It seems to me that I 
have to perform an awkward test to determine whether to execute a 
query with one question mark or two.


def lookupxy(x, y):
if y:
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 
= ?,

 (x, y))
else:
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 
IS NULL,

 (x,))

The more question marks involved the more complicated this would get, 
especially if question marks in the middle of several would sometimes 
need to be NULL. I hope I'm missing something and that someone can 
tell me what it is.
  




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


Re: How to Spawn a process with P_NOWAIT and pass it some data ?

2009-05-20 Thread MRAB

Barak, Ron wrote:

Hi,
 
This is my first try at IPC in Python, and I would like to ask your help 
with the following problem:
 
I would like to spawn a process with P_NOWAIT, and pass some data to the 
child process.
 
I created two scripts to try IPC (in a blocking way):
 
$ cat subprocess_sender.py

#!/usr/bin/env python
 
import subprocess
 
proc = subprocess.Popen([python, -u, subprocess_receiver.py], 
stdin=subprocess.PIPE, shell=True)
 
proc.communicate(input=this is sent from subprocess_sender.py)[0]

proc.stdin.close()
and
 
$ cat subprocess_receiver.py

#!/usr/bin/env python
 
import sys
 
print sys.stdin.readline()

These scripts intercommunicate nicely:
 
$ python -u  subprocess_sender.py

this is sent from subprocess_sender.py
The example in the documentation is:


  18.1.3.4. Replacing the os.spawn family¶
  
http://docs.python.org/library/subprocess.html#replacing-the-os-spawn-family

P_NOWAIT example:

pid = os.spawnlp(os.P_NOWAIT, /bin/mycmd, mycmd, myarg)
==
pid = Popen([/bin/mycmd, myarg]).pid


[snip]
The documentation is showing the 'subprocess' equivalents of older calls
(the 'subprocess' module was added in Python 2.4).

This means is that Popen is equivalent to calling spawnlp with
P_NOWAIT.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Marco Mariani

Mitchell L Model wrote:


def lookupxy(x, y):
if y:
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 = ?,
 (x, y))
else:
conn.execute(SELECT * FROM table WHERE COL1 = ? AND COL2 IS NULL,
 (x,))


The more question marks involved the more complicated this would get, especially if question marks in the middle of several would sometimes need to be NULL. 



With SQLAlchemy you could write:

table.select().where((table.c.col1==x)  (table.c.col2==y))

where x or y are None, the sql engine generates the appropriate IS 
NULL clause.




I hope I'm missing something and that someone can tell me what it is.



Yes, you are missing SQLAlchemy ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a Par construct to Python?

2009-05-20 Thread Grant Edwards
On 2009-05-20, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote:

 Any Python function that isn't calling a library function written in C
 that releases the GIL won't show any speedup will it?

 Not necessarily. Here's another function, that uses a loop instead of 
 sleep.

 def g(arg, SIZE=8*10**6):
 # Default SIZE is chosen so that on my machine, the loop 
 # takes approximately 0.5 second.
 for x in xrange(SIZE):
 pass
 return 3*arg-2


 setup = 'from __main__ import pmap, g; data = range(50)'
 min(Timer('map(g, data)', setup).repeat(repeat=5, number=3))
 65.093590974807739
 min(Timer('pmap(g, data)', setup).repeat(repeat=5, number=3))
 20.268381118774414

I find that surprising.  Evidently my understanding of the GIL
is wrong.

 I don't have a multi-core machine to try it on, but what
 happens when you replace your slow function code with
 something that actually burns CPU using pure-Python code
 instead of blocking on a timer in the OS?

 Two simple work-arounds are:

 * use Jython or IronPython; or

 * insert time.sleep(0.01) into your function at various points.

While the latter will allow thread switching, I don't see how
it will increase thread parallelism.

-- 
Grant Edwards   grante Yow! WHO sees a BEACH BUNNY
  at   sobbing on a SHAG RUG?!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


2d barcode library?

2009-05-20 Thread Trevor
Is anyone aware of a good library for building 2d barcodes (any format
will work for me) and outputing them as some picture format,
presumably png or bmp to be used for html printing? For 1D barcodes a
simple barcode font will suffice, but obviously 2D is not so simple
and i have yet to find the appropriate tool for use in a python
project...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2d barcode library?

2009-05-20 Thread Christian Heimes
Trevor schrieb:
 Is anyone aware of a good library for building 2d barcodes (any format
 will work for me) and outputing them as some picture format,
 presumably png or bmp to be used for html printing? For 1D barcodes a
 simple barcode font will suffice, but obviously 2D is not so simple
 and i have yet to find the appropriate tool for use in a python
 project...

huBarcode [1[ works well for me. It supports qrcode and datamatrix 2d
barcodes. I was able to scan the generated barcodes with my mobile
phone, even from my LCD screen.

Christian

[1] https://cybernetics.hudora.biz/projects/wiki/huBarcode

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


Re: Conceptual flaw in pxdom?

2009-05-20 Thread Paul Boddie
On 20 Mai, 11:25, Diez B. Roggisch de...@nospam.web.de wrote:

 Also, not trying to convince people that there are better alternatives to
 what and how they do something (admittedly, better is subjective, thus
 ensues discussion), or gathering arguments on why they do believe their way
 is preferable is the very essence of fora like this - if you'd really want
 that to go away, we're down to answering the notorious
 mutable-default-argument-question.

Yes, but the inquirer wasn't asking for general advice on what to use.
Again, if you're intending to use (or are constrained to using) one
thing, having people tell you to use something else has limited
benefits. I don't necessarily agree with the statements about the DOM
being particularly well thought out, but those were made to the
already-issued tangential advice which seems to be the norm on python-
list/comp.lang.python.

It's nice to see that one person responded to the inquirer's original
message, anyway, rather than attempt to educate him under the
assumption that he doesn't at all know what he's doing. In Google
Groups, you can see the profile of people and work out what they
seem to know fairly easily - a useful tool for anyone who doesn't
remember who asked what. Maybe some liberal usage of tools like that
would have saved us eight or so messages in this thread already.

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


popen - reading strings - constructing a list from the strings

2009-05-20 Thread Aytekin Vargun
 python-list@python.org
Hello everybody,
I have a question about the way I use os.popen. I am open to other
alternative suggestions like using subprocess or communicate.

I have an executable (say read_cell_types.exe) that produces string outputs.
For example, after one execution I got the following outputs in one line:

Neurons Microglia Astrocytes

In another execution, there might be different numbers of strings.

What I would like to do is to get these strings after running
read_cell_types.exe from my python program dynamically  and construct radio
buttons from the list of strings. In order to do this I need to construct a
list of strings first as in

[Neurons Microglia Astrocytes]

Then it is easy to construct the radio buttons.

When I use the following code

command = read_cell_types  + fileName2
child = os.popen(command)
data = child.read()
allObjects=data

allObjects (or data) contains the letters of all string words. I think it is
probably like [N e u r  ...]

How can I construct [Neurons Microglia Astrocytes] instead?

I will really appreciate your help.
Thanks a lot.

PS: fileName2 is a parameter  that I am passing to read_cell_types.exe

Aytekin

-- 
My web page: http://www.cs.rpi.edu/~vargua
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding repeated data sequences in a column

2009-05-20 Thread norseman

bearophileh...@lycos.com wrote:

yadin:

How can I build up a program that tells me that this sequence
128706
128707
128708
is repeated somewhere in the column, and how can i know where?


Can such patterns nest? That is, can you have a repeated pattern made
of an already seen pattern plus something else?
If you don't want a complex program, then you may need to specify the
problem better.

You may want something like LZ77 or releated (LZ78, etc):
http://en.wikipedia.org/wiki/LZ77
This may have a bug:
http://code.activestate.com/recipes/117226/

Bye,
bearophile


index on column
Ndx1 is set to index #1
Ndx2 is set to index #2
test Ndx1 against Ndx2
  if equal write line number and column content to a file
  (that's two things on one line:  15 128706
  283 128706 )
  Ndx1 is set to Ndx2
  Ndx2 is set to index #next
loop to testwriting out each duplicate set

Then use the outfile and index on line number

In similar manor, check if line current and next line line numbers are 
sequential.  If so scan forward to match column content of lower line 
number and check first matched column's line number and next for 
sequential.  Print them out if so



everything in outfile has 1 or more duplicates

4  aa   |--
5  bb |--  |  thus 4/5 match 100/101
6  cc| |
.| |
100 aa   |  |--
101 bb |--
102 ddd
103 cc  there is a duplicate but not a sequence
200 ff

mark duplicate sequences as tested and proceed on through
  seq1 may have more than one other seq in file.
  the progress is from start to finish without looking back
  thus each step forward has fewer lines to test.
  marking already knowns eliminates redundant sequence testing.

By subseting on pass1 the expensive testing is greatly reduced.
If you know your subset data won't exceed memory then the outfile
can be held in memory to speed things up considerably.

Today is: 20090520
no code

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


Re: Trying to understand a very simple class - from the book dive into python

2009-05-20 Thread Diez B. Roggisch
walterbyrd wrote:

 On May 20, 9:59 am, Marco Mariani ma...@sferacarta.com wrote:
 
 Do you know what a dictionary is?
 
 Yes, but I thought  a dictionary used curly brackets. Is the object a
 dictionary?

foo = {key : i'm the value of a dictionary}
print foo[key]

I suggest you read the tutorial:

http://docs.python.org/tutorial/datastructures.html#dictionaries

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


LaTeXing python programs

2009-05-20 Thread Edward Grefenstette
Yes, I am aware that this is more of a LaTeX question than a python
question, but I thought users here might be most likely to offer a
suitable recommendation.

I'm typing up my master's  thesis and will be including some of the
code used for my project in an appendix. The question is thus: is
there a LaTeX package out there that works well for presenting python
code?

verbatim is a bit ugly and doesn't wrap code, and while there are a
plethora of code colouring packages out there, they are not all easy
to use, so I thought I might ask what the popular options in the
community are.

Cheers,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a Par construct to Python?

2009-05-20 Thread Luis Zarrabeitia
On Monday 18 May 2009 10:31:06 pm Carl Banks wrote:
 Even if you decided to accept the penalty and add locking to
 refcounts, you still have to be prepared for context switching at any
 time when writing C code, which means in practice you have to lock any
 object that's being accessed--that's in addition to the refcount lock.

While I agree that the GIL greatly simplifies things for the interpreter, I 
don't understand this statement. In practice, you should lock all critical 
sections if you expect your code to be used in a multithreading environment. 
That can't be different from what Java, C# or any other languages do, 
including C++. Why is that so expensive in python extensions, that it is used 
as an argument against removing the GIL?

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LaTeXing python programs

2009-05-20 Thread John Reid

Edward Grefenstette wrote:

I'm typing up my master's  thesis and will be including some of the
code used for my project in an appendix. The question is thus: is
there a LaTeX package out there that works well for presenting python
code?

verbatim is a bit ugly and doesn't wrap code, and while there are a
plethora of code colouring packages out there, they are not all easy
to use, so I thought I might ask what the popular options in the
community are.


pygments

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


Re: popen - reading strings - constructing a list from the strings

2009-05-20 Thread MRAB

Aytekin Vargun wrote:

First of all,
Thanks for the suggestions, MRAB and norseman. split() was what I was 
looking for. Now I have a follow up question. In my application I create 
radio buttons in a frame. These radio buttons are constructed whenever a 
button is clicked. Therefore the list of items are dynamically changing.


What I want to do is to remove the current radio buttons and then 
recreate a new set of radio buttons using a new string list. I could not 
see a command for deleting or removing a set of radio buttons. I use 
Tkinter.


I can provide more details.
Thanks a lot.

PS: I apologize if this creates a new thread. I am new to the list.
Aytekin


I have no idea whether this is possible. I'd just create a new frame. I
hope you're not trying to add and remove buttons on a dialog while it's
open; having a dialog radically change its appearance while the user is
watching would, IMHO, be very bad! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: popen - reading strings - constructing a list from the strings

2009-05-20 Thread Aytekin Vargun
First of all,
Thanks for the suggestions, MRAB and norseman. split() was what I was
looking for. Now I have a follow up question. In my application I create
radio buttons in a frame. These radio buttons are constructed whenever a
button is clicked. Therefore the list of items are dynamically changing.

What I want to do is to remove the current radio buttons and then recreate a
new set of radio buttons using a new string list. I could not see a command
for deleting or removing a set of radio buttons. I use Tkinter.

I can provide more details.
Thanks a lot.

PS: I apologize if this creates a new thread. I am new to the list.
Aytekin


On Wed, May 20, 2009 at 11:17 AM, Aytekin Vargun varg...@gmail.com wrote:

 python-list@python.org
 Hello everybody,
 I have a question about the way I use os.popen. I am open to other
 alternative suggestions like using subprocess or communicate.

 I have an executable (say read_cell_types.exe) that produces string
 outputs. For example, after one execution I got the following outputs in one
 line:

 Neurons Microglia Astrocytes

 In another execution, there might be different numbers of strings.

 What I would like to do is to get these strings after running
 read_cell_types.exe from my python program dynamically  and construct radio
 buttons from the list of strings. In order to do this I need to construct a
 list of strings first as in

 [Neurons Microglia Astrocytes]

 Then it is easy to construct the radio buttons.

 When I use the following code

 command = read_cell_types  + fileName2
 child = os.popen(command)
 data = child.read()
 allObjects=data

 allObjects (or data) contains the letters of all string words. I think it
 is probably like [N e u r  ...]

 How can I construct [Neurons Microglia Astrocytes] instead?

 I will really appreciate your help.
 Thanks a lot.

 PS: fileName2 is a parameter  that I am passing to read_cell_types.exe

 Aytekin

 --
 My web page: http://www.cs.rpi.edu/~varguahttp://www.cs.rpi.edu/%7Evargua




-- 
My web page: http://www.cs.rpi.edu/~vargua
-- 
http://mail.python.org/mailman/listinfo/python-list


reseting an iterator

2009-05-20 Thread Jan
Wouldn't it be easy for Python to implement generating functions so
that the iterators they return are equipped with a __reset__() method?

Here is the context of this question.

Python documentation defines  a iterator as an object ITERATOR
having methods __next__() and __iter__() such that the call
ITERATOR.__iter__() returns the object itself, and once a call
ITERATOR. __next__() raises StopIteration every such subsequent call
does the same.

Python iterators model generating Turing machines, i.e.
deterministic Turing machines which take no input, which have a
separation symbol # in the output alphabet; have an one-way-infinite
output tape on which the output head prints and moves only to the
right; The machine may have a halting state; a word is said to be
generated by M if it appears on the output tape delimited by
separation symbols # (independently of whether M halts or computes
infinitely). Generating Turing machines provide a characterization of
recursively enumerable languages: a language is generated by a
generating Turing machine iff it is accepted by a Turing machine.

Turing machines can take as input and run other Turing Machines --
similarly Python functions can take other functions (including
iterators) as parameters and call them. HOWEVER, this symmetry breaks
down: a Turing machine which takes a generating Turing machine M as
input can run M for a number of steps and then RESET M and run it
again, while iterators as currently defined in Python do not have a
reset method. (I realize that instead of reseting an old iterator, one
can make a new iterator but it is not as elegant.)

(Contrary to Python's philosophy that there should be one-- and
preferably only one --obvious way to do it) there are several ways to
define iterators:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding repeated data sequences in a column

2009-05-20 Thread Tim Chase

lets say you have this column of numbers

128706
128707
128708
100
12
128706
128707
128708
128709
128706
128707
128708
100
12
6

How can I build up a program that tells me that this sequence
128706
128707
128708
is repeated somewhere in the column, and how can i know where?


In your example, would 100,12 also be output, or do you only 
care about the first find?  Do you have a minimum or maximum 
number of repeats you care about?  Is a repeated number a 
sequence of length 1?  Can it be capped to know that if you 
have more than N items in common, you don't have to compare more 
than N items from the entire pair of sequences?


-tkc



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


Re: LaTeXing python programs

2009-05-20 Thread José Matos
On Wednesday 20 May 2009 18:43:21 Edward Grefenstette wrote:
 Yes, I am aware that this is more of a LaTeX question than a python
 question, but I thought users here might be most likely to offer a
 suitable recommendation.

 I'm typing up my master's  thesis and will be including some of the
 code used for my project in an appendix. The question is thus: is
 there a LaTeX package out there that works well for presenting python
 code?

 verbatim is a bit ugly and doesn't wrap code, and while there are a
 plethora of code colouring packages out there, they are not all easy
 to use, so I thought I might ask what the popular options in the
 community are.

Use the listings package.
It has a python as one of defined languages and has lots of other options.
http://www.ctan.org/tex-archive/macros/latex/contrib/listings/

 Cheers,
 Edward

-- 
José Abílio
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I make pprint do this

2009-05-20 Thread skip
 I cannot get pprint to format output how I would like. pydb does. I
 tried grepping the source but still couldn't grok it.

That's not the way pprint works.  You have no control over how it arranges
its output.  If you need something more flexible you'll have to roll your
own.

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/
America's vaunted free press notwithstanding, story ideas that expose
the unseemly side of actual or potential advertisers tend to fall by the
wayside.  Not quite sure why.  -- Jim Thornton
-- 
http://mail.python.org/mailman/listinfo/python-list


Trying to understand a very simple class - from the book dive into python

2009-05-20 Thread walterbyrd
Example 5.6. Coding the FileInfo Class
class FileInfo(UserDict):
store file metadata
def __init__(self, filename=None):
UserDict.__init__(self)(1)
self[name] = filename(2)


What I do not understand is the last line. I thought 'self' was
supposed to refer to an instance of the object. But the square
brackets seem to indicate a list. Except you can not assign values to
a list like that. So where does name come from?

I am sure this is totally simple, but I missing something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reseting an iterator

2009-05-20 Thread Jan
On May 20, 2:35 pm, Jan jan.pl...@plattsburgh.edu wrote:

OOPS, I have pressed some keys and the message went out before It was
finished.
Here is the last fragment:

So, one can define iterators by defining a class whose objects have
methods
__iter__ and __next__ -- with this approach it is easy to add some
__reset__
method. But the easiest way to define iterators is by constructing a
generating
function (with yield expressions); this function returns iterators,
although
without __reset__. Another way to define an iterator is to define
callable
and using iter(CALLABLE, SENTINEL) -- the resulting iterator will not
have __reset__.
I do not know how Python is implemented but I believe that
in the last two cases, Python could produce improved iterators with
__reset__
at almost no additional cost.

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


Ann: Nucular full text search 0.5 +boolean queries +unicode fixes

2009-05-20 Thread Aaron Watters
Announcing Nucular 0.5

This release adds streamlined interfaces for
boolean queries.  Search for dogs or cats
but not smelly like this:

  dicts = session.dictionaries((dogs|cats) ~smelly)

Also included are some other features and bug
fixes, including some unicode handling bugfixes.

   HOME: http://nucular.sourceforge.net/
   BOOLEAN QUERIES: http://nucular.sourceforge.net/Boolean.html

About Nucular:

Nucular is a system for creating full text indices
for fielded data.  It can be accessed via a Python API
or via a suite of command line interfaces.

Nucular archives fielded documents and retrieves them
based on field value, field prefix, field word prefix,
or full text word prefix, word proximity or combinations of
these. Nucular also includes features for determining values
related to a query often called query facets.

Features

Nucular is very light weight. Updates and accesses
do not require any server process or other system
support such as shared memory locking.

Nucular supports concurrency. Arbitrary concurrent
updates and accesses by multiple processes or threads
are supported, with no possible locking issues.

Nucular is pure Python.
Nucular indexes and retrieves data quickly.
Nucular has a funny name.

More information about Nucular including links
to documentation, and releases is available at
http://nucular.sourceforge.net

Thanks: Rene Maurer and Matt Chaput and others
for comments, suggestions, patches.

   -- Aaron Watters

===
an apple every 8 hours
will keep 3 doctors away.  -- kliban
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The ultimate in voice-powered scripting in Windows... need help

2009-05-20 Thread John Doe

The author provided solutions.
Posted to (comp.lang.beta).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding repeated data sequences in a column

2009-05-20 Thread bearophileHUGS
yadin:
 How can I build up a program that tells me that this sequence
 128706
 128707
 128708
 is repeated somewhere in the column, and how can i know where?

Can such patterns nest? That is, can you have a repeated pattern made
of an already seen pattern plus something else?
If you don't want a complex program, then you may need to specify the
problem better.

You may want something like LZ77 or releated (LZ78, etc):
http://en.wikipedia.org/wiki/LZ77
This may have a bug:
http://code.activestate.com/recipes/117226/

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I make pprint do this

2009-05-20 Thread Robert Kern

On 2009-05-20 10:37, s...@pobox.com wrote:

   I cannot get pprint to format output how I would like. pydb does. I
   tried grepping the source but still couldn't grok it.

That's not the way pprint works.  You have no control over how it arranges
its output.  If you need something more flexible you'll have to roll your
own.


Or use Armin Ronacher's excellent pretty.py:

  http://dev.pocoo.org/hg/sandbox/file/tip/pretty

--
Robert Kern

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

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


Re: Trying to understand a very simple class - from the book dive into python

2009-05-20 Thread Marco Mariani

walterbyrd wrote:

 I am sure this is totally simple, but I missing something.

Do you know what a dictionary is?

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


Re: Import and absolute file names, sys.path including ''... or not

2009-05-20 Thread Aahz
In article mailman.406.1242754524.8015.python-l...@python.org,
Jean-Michel Pichavant  jeanmic...@sequans.com wrote:

I spent quite a time on a malicious issue. I found out that there is a
slight difference on the sys.path content when either executing code
from a shell or from within a script.  This difference is the '' item,
which is present in the shell form of sys.path.

Why are you calling this a malicious issue?

When I do this test, I find that the current working directory's full
path is prepended to sys.path, so if you're having problems, I bet that
you're changing your working directory during program execution.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

A foolish consistency is the hobgoblin of little minds, adored by little
statesmen and philosophers and divines.  --Ralph Waldo Emerson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reseting an iterator

2009-05-20 Thread Jan
On May 20, 2:48 pm, Jan jan.pl...@plattsburgh.edu wrote:

Iterators can also be produced by iter(ITERABLE) which
could mnufacture them with a __reset__.

Jan


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


Re: popen - reading strings - constructing a list from the strings

2009-05-20 Thread norseman

MRAB wrote:

Aytekin Vargun wrote:

mailto:python-list@python.org
Hello everybody,
I have a question about the way I use os.popen. I am open to other 
alternative suggestions like using subprocess or communicate.


I have an executable (say read_cell_types.exe) that produces string 
outputs. For example, after one execution I got the following outputs 
in one line:


Neurons Microglia Astrocytes

In another execution, there might be different numbers of strings.

What I would like to do is to get these strings after running 
read_cell_types.exe from my python program dynamically  and construct 
radio buttons from the list of strings. In order to do this I need to 
construct a list of strings first as in


[Neurons Microglia Astrocytes]

Then it is easy to construct the radio buttons.

When I use the following code

command = read_cell_types  + fileName2   child = 
os.popen(command)

data = child.read()
allObjects=data

allObjects (or data) contains the letters of all string words. I think 
it is probably like [N e u r  ...]


How can I construct [Neurons Microglia Astrocytes] instead?

I will really appreciate your help.
Thanks a lot.

PS: fileName2 is a parameter  that I am passing to read_cell_types.exe


If the words in the string are separated by whitespace then use
allObjects.split().

=
From actual code:
Python 2.5.2 with Tkinker supplied with download
Linux Slackware 10.2
Same files tested with identical results on Windows XP Pro
  (the .bin was changed to use the .exe compile on Window$ :)


import os

Scenario 1
  requiredoptional optional
  .exe file   token(s) redirected output
xx= os.popen(shp2dxf.bin al963424.shp al963424.dxf).readlines()

Then use the output file any way you want.
   --

Scenerio 2
xx= os.popen(shp2dxf.bin al963424.shp).readlines()

for i in xx:
  print \t+i[:-1]


change the print to the code to process your strings (0r don't and use
it to show progress and just add code to process your strings.)

   --

The processed strings can be formatted into a list like below.  The
code (left side) can be left blank and you can fill it in manually or
numbers can be used or whatever you like. In this example, the right
side is what I want to be on the button(s).
 (string, same_string) is OK too.

  AttTyp = [
(S, Single Use),
(I, Intercropping),
(D, Double Cropping),
(T, Triple Cropping),
(M, Mixed Land Use),
(-,---),
(t, Toggle Table Display),
  ]


Next, this will read the above list and generate the actual buttons if
you are using Tkinter.

  AttB= []
  for mode, text in AttTyp:
c= Radiobutton(frameAtt, text=text, indicatoron=0,
 variable=AttVal, value=mode, command=getAttTyp)
AttB.append(c)
c.pack()
  AttB[5].config(state = DISABLED)  #grays out button
  AttB[6].config(state = DISABLED)  #(state= NORMAL) returns to live


Using the append() allows button control from other parts of the
program. It is not required for the buttons to work, but good to have.
*variable* is what is passed to python. AttVal in the example.
Python reads it by using AttVal.get(). As in if AttVal.get() == ??..
or perhaps  local_var_in_function= AttVal.get().
If you reverse the variables mode and text in the 'for mode...' line
then you need to reverse the two strings on each line of the feed list.
(Or exchange their places in the assignment section :)

Using mode and text as the vars, text goes on the button for the human
to read and mode is the internal value to test to determine which
button got pressed. The names mode and text are arbitrary. Name them as
you wish but place each appropriately in the assignment section.


Happy coding.

Today is 20090520
Steve


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


Re: Adding a Par construct to Python?

2009-05-20 Thread Paul Boddie
On 20 Mai, 15:01, Iain King iaink...@gmail.com wrote:

 I was going to write something like this, but you've beat me to it :)
 Slightly different though; rather than have pmap collate everything
 together then return it, have it yield results as and when it gets
 them and stop iteration when it's done, and rename it to par to keep
 the OP happy and you should get something like what he initially
 requests (I think):

 total = 0
 for score in par(f, data):
     total += score

It depends on whether you want the outputs to correspond to the inputs
in the resulting sequence. If pmap is supposed to behave like map, you
want the positions of each input and corresponding output to match. As
I wrote earlier, in pprocess you distinguish between these cases by
employing maps (for input/output correspondence) and queues (for
first ready behaviour).

I don't recall whether the Map class in pprocess blocks for all the
data to be returned, or whether you can consume any outputs that are
at the start of the output sequence (and then block until output
arrives at the next available position), but this would be a logical
enhancement.

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


Re: Is there a better way to chose a slice of a list?

2009-05-20 Thread walterbyrd
On May 19, 5:31 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:

 That's just the same micro-goal re-stated. What is your larger problem
 of which this is a part? Perhaps a better approach can be suggested when
 that context is known.

I am processing a huge spreadsheet which I have converted to a csv
format. Each row will be a wiki page with several sub-headings. The
spreadsheet contains information about servers. Wiki sub-headings may
include: 'hardware', 'software', 'users', 'network swith settings'.
'Hardware' may include the spreadsheet columns: 'memory', 'cpu', and
so on. So the first six columns in the spreadsheet may go under
'hardware' the next six under 'software' and so on.

I have already created the wiki pages, using a method similar to what
I first posted. But, it seems like there should be a better way to to
do it. So, for future reference, I was just wondering.

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


When does the escape character work within raw strings?

2009-05-20 Thread walterbyrd
I know that

s = r'x\nx'

means 'x' followed by a literal '\' followed by an 'n' (the '\n' is
not a carriage return).

s = r'x\tx'

means 'x' followed by a literal '\' followed by an 't' (the '\t' is
not a tab).

But, boundries seem to work differently.

s = re.sub(r'\bxxx\b', 'yyy', s)

Is *not* going to look for a literal '\' followed by 'b'

So I am confused about when escapes work within raw strings, and when
do escapes not work within raw strings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding repeated data sequences in a column

2009-05-20 Thread yadin
On May 20, 11:16 am, bearophileh...@lycos.com wrote:
 yadin, understanding what you want is probably 10 times harder than
 writing down the code :-)

  I have a a table, from where I can extract a column.

 You can extract it? Or do you want to extract it? Or do you want to
 process it? Etc.

  I wanna go down trough that column made of numbers
  examine undetermined chunks ofdataand see or detect if that sequence
  of chunk
  ofdatahas beenrepeatedbefore

 What do you mean by undetermined? What kind ofdata? Where is thisdata? How 
 is this chunk shaped? Are you talking about a string?

  and if it has beenrepeateddetect it by giving it a name in an
  adjacent column.

 What kind of name? So you just need 2 names, like N and S for New and
 Seen?
 You can use a built-in setdatastructure to know if you have already
 seen somedata, while you scan the records.

  Imagine someting like this but made of 1800 numbers...

 How are such 1800 disposed? Do you mean 1800 columns of 32 bit
 numbers?

  how can I build up column 3(category)

 What does A, B and C mean?

 Bye,
 bearophile

lets say you have this column of numbers

128706
128707
128708
100
12
128706
128707
128708
128709
128706
128707
128708
100
12
6

How can I build up a program that tells me that this sequence
128706
128707
128708
is repeated somewhere in the column, and how can i know where?

thank you very much!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand a very simple class - from the book dive into python

2009-05-20 Thread walterbyrd
On May 20, 9:59 am, Marco Mariani ma...@sferacarta.com wrote:

 Do you know what a dictionary is?

Yes, but I thought  a dictionary used curly brackets. Is the object a
dictionary?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen - reading strings - constructing a list from the strings

2009-05-20 Thread MRAB

Aytekin Vargun wrote:

mailto:python-list@python.org
Hello everybody,
I have a question about the way I use os.popen. I am open to other 
alternative suggestions like using subprocess or communicate.


I have an executable (say read_cell_types.exe) that produces string 
outputs. For example, after one execution I got the following outputs in 
one line:


Neurons Microglia Astrocytes

In another execution, there might be different numbers of strings.

What I would like to do is to get these strings after running 
read_cell_types.exe from my python program dynamically  and construct 
radio buttons from the list of strings. In order to do this I need to 
construct a list of strings first as in


[Neurons Microglia Astrocytes]

Then it is easy to construct the radio buttons.

When I use the following code

command = read_cell_types  + fileName2   
child = os.popen(command)

data = child.read()
allObjects=data

allObjects (or data) contains the letters of all string words. I think 
it is probably like [N e u r  ...]


How can I construct [Neurons Microglia Astrocytes] instead?

I will really appreciate your help.
Thanks a lot.

PS: fileName2 is a parameter  that I am passing to read_cell_types.exe


If the words in the string are separated by whitespace then use
allObjects.split().
--
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand a very simple class - from the book dive into python

2009-05-20 Thread Chris Rebert
On Wed, May 20, 2009 at 9:10 AM, walterbyrd walterb...@iname.com wrote:
 On May 20, 9:59 am, Marco Mariani ma...@sferacarta.com wrote:

 Do you know what a dictionary is?

 Yes, but I thought  a dictionary used curly brackets. Is the object a
 dictionary?

Indeed. Note how you're subclassing `UserDict` (its name is similar to
`dict` for a reason).
See the UserDict docs for more info:
http://docs.python.org/library/userdict.html

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance java vs. python

2009-05-20 Thread namekuseijin
On Tue, May 19, 2009 at 7:21 PM, David Stanek dsta...@dstanek.com wrote:
 On Tue, May 19, 2009 at 5:43 PM, namekuseijin namekusei...@gmail.com wrote:
 someone said:

 If you took a look at Java, you would
 notice that the core language syntax is much simpler than Python's.

 thanks for the laughs whoever you are!


 I'm no Java fan, but I do agree that the core language is a bit easier
 for people to grasp. I have also heard that from other developers as
 well.

Really?  Core language, eh?

Just take a look at just the summary of the Java language spec:
http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

Then compare with the summary for Python 3.0 language reference:
http://docs.python.org/3.0/reference/

Like comparing a mammoth to a zebra.

Besides, how is:
for( int i=0; i10; i++ )

simpler than:
for i in (range(10))

?

Scripting languages like Python eventually led Java to provide a more
friendly for, which they call, quite appropriately, enhacedFor.
Here's it in action:
for (Map.EntryString, Integer e : histogram.entrySet())

in Python:
for e in histogram.items()

fun.

Here's a more complete example, available a bit down from:
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2

MapString, Integer histogram = ...;
double total = 0;
for (int i : histogram.values())
total += i;
for (Map.EntryString, Integer e : histogram.entrySet())
System.out.println(e.getKey() + + e.getValue() / total);

in Python:
histogram = ...
total=0
for i in histogram.values():  total+=i
for e in histogram.items():
print(  e[0] +   + str( e[1]/float(total) ))

yeah, surely a friggin' lot more complex... and we didn't even come to
use any of Java's HUUUGE APIs, just the core lang... BTW, I'm amused
that Java's string concatanating doesn't require an explicit cast from
the float result.

anyway, again, thanks for the laughs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When does the escape character work within raw strings?

2009-05-20 Thread MRAB

walterbyrd wrote:

I know that

s = r'x\nx'

means 'x' followed by a literal '\' followed by an 'n' (the '\n' is
not a carriage return).

s = r'x\tx'

means 'x' followed by a literal '\' followed by an 't' (the '\t' is
not a tab).

But, boundries seem to work differently.

s = re.sub(r'\bxxx\b', 'yyy', s)

Is *not* going to look for a literal '\' followed by 'b'

So I am confused about when escapes work within raw strings, and when
do escapes not work within raw strings.


The re module receives the regular expression in the form of a string
and then interprets it in its own way.

If you give the re module '\b', that's a backspace character, which is
treated as a literal character, just like 'x'.

If you give it r'\b', that _does_ contain 2 characters, but the re
module interprets it as representing a word boundary, except in a
character set [...] where that would be meaningless, so there it's
interpreted as representing a backspace character.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [unladen-swallow] PEP 384: Defining a Stable ABI

2009-05-20 Thread Jeffrey Yasskin
A couple thoughts:

I'm with the people who think the refcount should be accessed through
functions by apps that want ABI compatibility. In particular,
GIL-removal efforts are guaranteed to change how the refcount is
modified, but there's a good chance they wouldn't have to change the
API. (We have some ideas for how to maintain source compatibility in
the absence of a GIL:
http://code.google.com/p/unladen-swallow/wiki/ExtensionModules#Reference_Counting)
Over an 8-year lifetime for Python 3, Moore's law predicts that
desktop systems will have up to 64 cores, at which point even the
simplest GIL-removal strategy of making refcounts atomic will be a
win, despite the 2x performance loss for a single thread. I wouldn't
want an ABI to rule that out.

I do think the refcounting macros should remain present in the API
(not ABI) for apps that only need source compatibility and want the
extra speed.

I wonder if it makes sense to specify an API compatibility mode in
this PEP too.

Py_LIMITED_API may not be the right macro name—it didn't imply
anything about an ABI when I first saw it. Might it make sense to use
Py_ABI_COMPATIBILITY=### instead? (Where ### could be an ISO date like
20090520.) That would put ABI in the macro name and make it easier
to define new versions later if necessary. (New versions would help
people compile against a new version of Python and be confident they
had something that would run against old versions.) If we never define
a new version, defining it to a number instead of just anything
doesn't really hurt.

It's probably worth pointing out in the PEP that the fact that
PyVarObject.ob_size is part of the ABI means that PyObject cannot
change size, even by adding fields at the end.

Right now, the globals representing types are defined like
PyAPI_DATA(PyTypeObject) PyList_Type;. To allow the core to use the
new type creation functions, it might be useful to make the ABI type
objects PyTypeObject* constants instead.

In general, this looks really good. Thanks!

Jeffrey

On Sun, May 17, 2009 at 1:54 PM, Martin v. Löwis mar...@v.loewis.de wrote:

 Thomas Wouters reminded me of a long-standing idea; I finally
 found the time to write it down.

 Please comment!

 Regards,
 Martin

 PEP: 384
 Title: Defining a Stable ABI
 Version: $Revision: 72754 $
 Last-Modified: $Date: 2009-05-17 21:14:52 +0200 (So, 17. Mai 2009) $
 Author: Martin v. Löwis mar...@v.loewis.de
 Status: Draft
 Type: Standards Track
 Content-Type: text/x-rst
 Created: 17-May-2009
 Python-Version: 3.2
 Post-History:

 Abstract
 

 Currently, each feature release introduces a new name for the
 Python DLL on Windows, and may cause incompatibilities for extension
 modules on Unix. This PEP proposes to define a stable set of API
 functions which are guaranteed to be available for the lifetime
 of Python 3, and which will also remain binary-compatible across
 versions. Extension modules and applications embedding Python
 can work with different feature releases as long as they restrict
 themselves to this stable ABI.

 Rationale
 =

 The primary source of ABI incompatibility are changes to the lay-out
 of in-memory structures. For example, the way in which string interning
 works, or the data type used to represent the size of an object, have
 changed during the life of Python 2.x. As a consequence, extension
 modules making direct access to fields of strings, lists, or tuples,
 would break if their code is loaded into a newer version of the
 interpreter without recompilation: offsets of other fields may have
 changed, making the extension modules access the wrong data.

 In some cases, the incompatibilities only affect internal objects of
 the interpreter, such as frame or code objects. For example, the way
 line numbers are represented has changed in the 2.x lifetime, as has
 the way in which local variables are stored (due to the introduction
 of closures). Even though most applications probably never used these
 objects, changing them had required to change the PYTHON_API_VERSION.

 On Linux, changes to the ABI are often not much of a problem: the
 system will provide a default Python installation, and many extension
 modules are already provided pre-compiled for that version. If additional
 modules are needed, or additional Python versions, users can typically
 compile them themselves on the system, resulting in modules that use
 the right ABI.

 On Windows, multiple simultaneous installations of different Python
 versions are common, and extension modules are compiled by their
 authors, not by end users. To reduce the risk of ABI incompatibilities,
 Python currently introduces a new DLL name pythonXY.dll for each
 feature release, whether or not ABI incompatibilities actually exist.

 With this PEP, it will be possible to reduce the dependency of binary
 extension modules on a specific Python feature release, and applications
 embedding Python can be made work with different releases.

 Specification

Re: package with executable

2009-05-20 Thread Stefano Costa
Il Wed, 20 May 2009 07:01:39 +0100, A. Cavallo ha scritto:

 With the standard distutils (no need for setuptools) the config.py file
 might look like:

Right, I ended up using setuptools just because I used paster to create 
the project layout. I'll think about using plain distutils instead.

 import gnucal must work. If you're developing from the sources (eg.
 without having the package installed) you need to be in the same dir
 where the gnucal.py is or you need to set PYTHONPATH in order to find
 the directory gnucal (the one containing __init__.py).

Right now, the problem is that upon installing import gnucal works in 
the python interactive interpreter, but gnucal.py raises an exception 
that it's not able to import gnucal.core and friends.

 At line 101 the statement sys.exit(Please.. should be
 parser.error(Please..

Good point! Thanks,
steko

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


Re: 2d barcode library?

2009-05-20 Thread Alan G Isaac

Christian Heimes wrote:

https://cybernetics.hudora.biz/projects/wiki/huBarcode



Cool.
I have to mention a pure PostScript writer as well:
http://www.terryburton.co.uk/barcodewriter/

Alan Isaac

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


Re: LaTeXing python programs

2009-05-20 Thread Alan G Isaac
On Wednesday 20 May 2009 18:43:21 Edward Grefenstette 
wrote:
is there a LaTeX package out there that works well for 
presenting python code? 



José Matos wrote:
Use the listings package. 
It has a python as one of defined languages and has lots of other options. 
http://www.ctan.org/tex-archive/macros/latex/contrib/listings/ 



The listings package is great and highly configurable.
Note that you can also input entire files of Python code
or pieces of them based on markers.  Really quite great.

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: reseting an iterator

2009-05-20 Thread Alan G Isaac

Jan wrote:

Wouldn't it be easy for Python to implement generating functions so
that the iterators they return are equipped with a __reset__() method?


Use ``send``:
http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features

Remember, there may be no underlying sequence object for
an iterator, and if you want one in that case, you should build it.

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


Re: Performance java vs. python

2009-05-20 Thread Ant
On May 20, 6:46 pm, namekuseijin namekusei...@gmail.com wrote:
 anyway, again, thanks for the laughs.

I'm a Java developer in my day job, and I use Jython for testing out
ideas and prototyping, due to the way Jython makes writing Java so
much easier... Those examples were spot on - things weren't much
simpler before generics, as you had casting going on everywhere. Not
to mention the nice primitive / object divide to add to the languages
complexity.

And the libraries in Java... Compare cat implementations:

# Python
fh = open(myfile.txt)

for line in fh:
print line

// Java

...

BufferedReader reader = new BufferedReader(new FileReader
(myfile.txt));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
}

...

And that's without all of the class/main method boilerplate or try
catch block required due to checked exceptions.

I've taught both Java and Python, and the latter is far easier to pick
up and run with, from both a syntactic point of view and in the use of
the libraries.


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


Re: Import and absolute file names, sys.path including ''... or not

2009-05-20 Thread Jean-Michel Pichavant
You are right, but my concern is not the relative path resolution. Let 
me clarify:


/home/jeanmichel/test.py:
import sys
print sys.path

python.exe test.py
sys.path = ['/home/jeanmichel']
 from within a python shell:
sys.path = ['']

The unpredictable effect of '' (at least something I did not predict) is 
that it allows absolute path resolution, while '/home/jeanmichel' cannot.

Example :
write a anotherTest.py file:

__import__('/home/jeanmichel/test')


anotherTest.py will be successfully imported in a python shell ('' + 
'/home/jeanmichel/test.py' is a valid path), but the python.exe 
anotherTest2.py  form will fail as it will try for '/home/jeanmichel' 
+'/home/jeanmichel/test.py' which is not a valid path.


So my question is: why the shell is adding '' when the interpreter is 
adding the full path ?


Hope I'm not too foggy.

JM

Aahz wrote:

In article mailman.406.1242754524.8015.python-l...@python.org,
Jean-Michel Pichavant  jeanmic...@sequans.com wrote:
  

I spent quite a time on a malicious issue. I found out that there is a
slight difference on the sys.path content when either executing code


from a shell or from within a script.  This difference is the '' item,
  

which is present in the shell form of sys.path.



Why are you calling this a malicious issue?

When I do this test, I find that the current working directory's full
path is prepended to sys.path, so if you're having problems, I bet that
you're changing your working directory during program execution.
  


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


Re: Performance java vs. python

2009-05-20 Thread namekuseijin

Ant escreveu:

# Python
fh = open(myfile.txt)

for line in fh:
print line

// Java

...

BufferedReader reader = new BufferedReader(new FileReader
(myfile.txt));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
}

...

And that's without all of the class/main method boilerplate or try
catch block required due to checked exceptions.


Indeed, and it's so complex and such a manual burden that you even 
forgot a further

line = reader.readLine();

inside your while block.

I find it completely unimaginable that people would even think 
suggesting the idea that Java is simpler.  It's one of the most stupidly 
verbose and cranky languages out there, to the point you can't really do 
anything of relevance without an IDE automatically pumping out lots of 
scaffold code for you.


--
a game sig: http://tinyurl.com/d3rxz9
--
http://mail.python.org/mailman/listinfo/python-list


URGENT! Changing IE PAC Settings with Python

2009-05-20 Thread K-Dawg
Hello,

Thanks for any response.  I am in a crisis where one of our networking guys
moved where our PAC file is housed.  There was a group policy set in Active
Directory that set the PAC file location in Internet Explorer to the new
location.

However, we have 100 remote centers that have about 3 to 4 machines that are
not on AD (from before an AD migration).  These machines did not receive the
update.

Is there a way I can write a python script to run from my machine to jump
out to a list
--
Kevin Holleran
Master of Science, Computer Information Systems
Grand Valley State University
Master of Business Administration
Western Michigan University
Completion December 2009
CCNA, ISA, MCSA, MCDST, MCP

We are what we repeatedly do. Excellence, then, is not an act, but a
habit. - Aristotle

A man flattened by an opponent can get up again. A man flattened by
conformity stays down for good.  - Thomas J. Watson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: P2P text chat engine

2009-05-20 Thread Diez B. Roggisch
Kirill wrote:

 On 7 май, 21:23, Diez B. Roggisch de...@nospam.web.de wrote:
 Navanjo schrieb:

  If you have the source code of a p2p text chat engine please send to me

 I found that  a pot of gold under my bed. Care to give me your address
 so that I can send it to you?

 SCNR,
 Diez
 
 Hello, can you sent it to me ?
 ave...@gmail.com
 Many thanks!!!

I need a snail-mail address of course, gold isn't really shippable via
email, you know?

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


Re: Seeking old post on developers who like IDEs vs developers who like simple languages

2009-05-20 Thread Steve Ferg
 I think you mean this clbuttic post:
 http://osteele.com/archives/2004/11/ides

That's it!  Thanks very much, Marco!!

It is good to read it again.  It is like visiting a place where you
grew up years ago, and finding that it is completely different than
the way you remember it.  It is surprising how much better it is than
my rather crude memory of it.

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


Re: Adding a Par construct to Python?

2009-05-20 Thread Carl Banks
On May 20, 8:59 am, Luis Zarrabeitia ky...@uh.cu wrote:
 On Monday 18 May 2009 10:31:06 pm Carl Banks wrote:

  Even if you decided to accept the penalty and add locking to
  refcounts, you still have to be prepared for context switching at any
  time when writing C code, which means in practice you have to lock any
  object that's being accessed--that's in addition to the refcount lock.

 While I agree that the GIL greatly simplifies things for the interpreter, I
 don't understand this statement. In practice, you should lock all critical
 sections if you expect your code to be used in a multithreading environment.
 That can't be different from what Java, C# or any other languages do,
 including C++. Why is that so expensive in python extensions, that it is used
 as an argument against removing the GIL?

I wasn't really arguing that locking individual objects was a
significant penalty in computer time, only in programmer time.  The
locks on reference counts are what's expensive.

Also, I'm not using it as an argument against removing the GIL.  I
want to remove the GIL.  I'm only pointing out that removing the GIL
is not easy, and once it's removed there is a cost.


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


Re: reseting an iterator

2009-05-20 Thread Terry Reedy

Jan wrote:

Wouldn't it be easy for Python to implement generating functions so
that the iterators they return are equipped with a __reset__() method?


No.  Such a method would have to poke around in the internals of the 
__next__ function in implementation specific ways.  The values used to 
initialize that function might have changed, so 'reset' would have to be 
carefully defined.


def squares():
  start = int(input(enter starting int:))
  stop  = int(input(enter stopping int))
  for i in range(start,stop):
yield i*i

What does 'reset' mean here?


Here is the context of this question.

Python documentation defines  a iterator as an object ITERATOR
having methods __next__() and __iter__() such that the call
ITERATOR.__iter__() returns the object itself, 


This is so that 'iter(iterator) is iterator', so that functions can take 
either an interable or iterator as an argument and proceed without 
checking which it got.



and once a call ITERATOR. __next__() raises StopIteration every

  such subsequent call does the same.

After returning objects for some number of calls, which might be unbounded.

The protocol is basically one method with defined behavior.  It is 
intentionally minimal so it can be used as the universal within-Python 
object stream protocol.  Multiple ways of getting interators is in line 
with this purpose.


Terry Jan Reedy

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


Streaming pdf with URLLib

2009-05-20 Thread Scooter
I'm playing around with urllib, and httplib, trying to make something
of a pdf proxy.I have a pdf that lives on an internal web server, and
I would like to be able to stream it to my external server. (this is
just a test for a bigger process. Yes I could just copy the pdf to the
external box). I was playing with URLLib doing something like

#!/usr/bin/python

import urllib

u = urllib.urlopen('https://myinternal.server/pdfs/pdfstreamer.aspx')
print 'Content-type: application/pdf\n\n'
# print 'Content-type: application/x-msdownload; name=\FileName\\n
\n'
# print 'Content-Dispostion: attachment; filename=\FileName\\r\n\n'

pdfdoc = u.read()
print pdfdoc

Hitting my pdfstreamer.aspx app directly through a browser renders a
pdf just fine. So now I'm attempting to use this python app on an
external webserver, access it as a cgi, to pull the pdf, and then re-
render it, but at that point it just shows me the raw pdf in
the browser.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LaTeXing python programs

2009-05-20 Thread John Reid


Alan G Isaac wrote:

The listings package is great and highly configurable.
Note that you can also input entire files of Python code
or pieces of them based on markers.  Really quite great.


I tried listings. I believe pygments makes better formatted output (at 
least out of the box).


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


Re: URGENT! Changing IE PAC Settings with Python

2009-05-20 Thread Tim Golden

K-Dawg wrote:

Thanks for any response.  I am in a crisis where one of our networking guys
moved where our PAC file is housed.  There was a group policy set in Active
Directory that set the PAC file location in Internet Explorer to the new
location.

However, we have 100 remote centers that have about 3 to 4 machines that are
not on AD (from before an AD migration).  These machines did not receive the
update.

Is there a way I can write a python script to run from my machine to jump
out to a list



More of a Windows question, really, and depends on the configuration
of network, security etc. Certainly you can use any of the usual
Windows techniques (UNCs, WMI, DCOM etc.) to invoke things on those remote
machines, assuming you have enough network and credentials to get there.

Not clear what your level of expertise is, either at the Windows
or at the Python level, so apols. if suggesting the obvious here.
If you already know what technique you're going to use to push
your file out (say, a copy to a remote unc) then getting Python to
read a list of machines from a file and doing the same to each one
is child's play:

import shutil
for machine in open (machines.txt):
 shutil.copyfile (local.pac, r\\%s\c$\somewhere\thing.pac % machine)

If you need to set up credentials for that connection first, you
might want to use the win32net module from the pywin32 extensions
to establish a mapped drive or at least a NULL session with known
credentials.

As a possibility the other way round, if you're able to WMI into
the machines, you could run a command on them to pull the file
in, rather than pushing. Obviously, you've still got to establish
credentials.

I'll stop there, because I might be missing the target altogether.
You'll certainly get help here, but you might want to post to
the python-win32 list which is a bit more specialised.

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


Re: URGENT! Changing IE PAC Settings with Python

2009-05-20 Thread James Matthews
HI forwarded it to the Python Win32 list

On Thu, May 21, 2009 at 12:11 AM, Tim Golden m...@timgolden.me.uk wrote:

 K-Dawg wrote:

 Thanks for any response.  I am in a crisis where one of our networking
 guys
 moved where our PAC file is housed.  There was a group policy set in
 Active
 Directory that set the PAC file location in Internet Explorer to the new
 location.

 However, we have 100 remote centers that have about 3 to 4 machines that
 are
 not on AD (from before an AD migration).  These machines did not receive
 the
 update.

 Is there a way I can write a python script to run from my machine to jump
 out to a list



 More of a Windows question, really, and depends on the configuration
 of network, security etc. Certainly you can use any of the usual
 Windows techniques (UNCs, WMI, DCOM etc.) to invoke things on those remote
 machines, assuming you have enough network and credentials to get there.

 Not clear what your level of expertise is, either at the Windows
 or at the Python level, so apols. if suggesting the obvious here.
 If you already know what technique you're going to use to push
 your file out (say, a copy to a remote unc) then getting Python to
 read a list of machines from a file and doing the same to each one
 is child's play:

 import shutil
 for machine in open (machines.txt):
  shutil.copyfile (local.pac, r\\%s\c$\somewhere\thing.pac % machine)

 If you need to set up credentials for that connection first, you
 might want to use the win32net module from the pywin32 extensions
 to establish a mapped drive or at least a NULL session with known
 credentials.

 As a possibility the other way round, if you're able to WMI into
 the machines, you could run a command on them to pull the file
 in, rather than pushing. Obviously, you've still got to establish
 credentials.

 I'll stop there, because I might be missing the target altogether.
 You'll certainly get help here, but you might want to post to
 the python-win32 list which is a bit more specialised.

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




-- 
http://www.goldwatches.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a Par construct to Python?

2009-05-20 Thread Luis Zarrabeitia
On Wednesday 20 May 2009 04:32:59 pm Carl Banks wrote:
 I wasn't really arguing that locking individual objects was a
 significant penalty in computer time, only in programmer time.  The
 locks on reference counts are what's expensive.

 Also, I'm not using it as an argument against removing the GIL.  I
 want to remove the GIL.  I'm only pointing out that removing the GIL
 is not easy, and once it's removed there is a cost.

Ah, allright then. Thanks for the clarification.

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
-- 
http://mail.python.org/mailman/listinfo/python-list


optparse question, passing unknown flags to subprocess

2009-05-20 Thread Joseph Garvin
I'm working on a python script that takes several command line flags,
currently parsed by hand. I'd like to change the script to parse them
with OptionParser from the optparse module. However, currently the
script invokes a subprocess, and any flags the script doesn't
understand it assumes are meant to be passed to the subprocess. But if
I switch to using OptionParser, any options I haven't added to my
parser will cause an error, instead of it ignoring those and letting
me pass them onto the subprocess.

What's the best/most-pythonic way to handle this? I could subclass
OptionParser and override its exit() and error() methods as suggested
by the docs 
(http://www.python.org/doc/2.4/lib/optparse-how-optik-handles-errors.html)
and have them do nothing, but there are some errors I probably don't
want to ignore (like if the user tries to pass a string to a known
flag that takes an int).
-- 
http://mail.python.org/mailman/listinfo/python-list


scoping problem with list comprehension // learning Python

2009-05-20 Thread Adrian Dragulescu


I just started to learn python (first posting to the list).

I have a list of dates as strings  that I want to convert to a 
list of datetime objects.  Here is my debugging session from inside a 
method.


(Pdb) formatIndex
'%Y-%m-%d'
(Pdb) [datetime.strptime(i, formatIndex) for i in self.index[0:3]]
*** NameError: global name 'formatIndex' is not defined
(Pdb) [datetime.strptime(i, '%Y-%m-%d') for i in self.index[0:3]]
[datetime.datetime(2007, 1, 3, 0, 0), datetime.datetime(2007, 1, 4, 0, 0), 
datetime.datetime(2007, 1, 5, 0, 0)]

(Pdb)

How come I get an error that formatIndex is not defined? I just show that 
it has value '%Y-%m-%d', in the same method scope.  Not sure why it says 
global name, as I am in a method.


If I run it as a stand-alone, it works:
  index = ['2007-01-01', '2007-01-02', '2007-01-03']
  formatIndex = '%Y-%m-%d'
  print([datetime.strptime(i, formatIndex) for i in index])

Any suggestions much appreciated.  I'm sure it's something trivial.  I'm 
using Python30.


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


Re: Performance java vs. python

2009-05-20 Thread Aahz
In article gv1nor$10u...@adenine.netfront.net,
namekuseijin  namekusei...@gmail.com wrote:

I find it completely unimaginable that people would even think 
suggesting the idea that Java is simpler.  It's one of the most stupidly 
verbose and cranky languages out there, to the point you can't really do 
anything of relevance without an IDE automatically pumping out lots of 
scaffold code for you.

Well, I wouldn't go quite that far; after all, I managed to integrate
BouncyCastle into a Java app without an IDE (or really knowing Java, for
that matter).  But you have a valid point once the excessive generalizing
is removed.  ;-)
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

A foolish consistency is the hobgoblin of little minds, adored by little
statesmen and philosophers and divines.  --Ralph Waldo Emerson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a Par construct to Python?

2009-05-20 Thread Aahz
In article mailman.449.1242835175.8015.python-l...@python.org,
Luis Zarrabeitia  ky...@uh.cu wrote:
On Monday 18 May 2009 10:31:06 pm Carl Banks wrote:

 Even if you decided to accept the penalty and add locking to
 refcounts, you still have to be prepared for context switching at any
 time when writing C code, which means in practice you have to lock any
 object that's being accessed--that's in addition to the refcount lock.

While I agree that the GIL greatly simplifies things for the
interpreter, I don't understand this statement. In practice, you should
lock all critical sections if you expect your code to be used in a
multithreading environment.  That can't be different from what Java, C#
or any other languages do, including C++. Why is that so expensive in
python extensions, that it is used as an argument against removing the
GIL?

Python is intended to be simple/easy to integrate with random C
libraries.  Therefore you have to write explicit code from the C side in
order to drop the GIL.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

A foolish consistency is the hobgoblin of little minds, adored by little
statesmen and philosophers and divines.  --Ralph Waldo Emerson
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >