ANN: eGenix mxODBC Connect Database Interface for Python 0.9.1 (beta)

2008-06-16 Thread eGenix Team: M.-A. Lemburg



ANNOUNCING
eGenix.com mxODBC Connect

  Database Interface for Python

   Version 0.9.1 (beta)


  Our new client-server product for connecting Python applications
 to relational databases - on all major platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Connect-0.9.1-beta.html



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.  This makes
mxODBC Connect the ideal basis for writing cross-platform database
programs and utilities in Python.

mxODBC Connect extends our eGenix mx Python Extension series with a
new client-server based product, that removes the need to install and
configure ODBC drivers on the client side. This greatly simplifies
setup and configuration of database driven client applications, while
at the same time making the network communication between client and
database server more efficient and more secure.

* About Python:
Python is an object-oriented Open Source programming language which
runs on all modern platforms (http://www.python.org/). By integrating
ease-of-use, clarity in coding, enterprise application connectivity
and rapid application design, Python establishes an ideal programming
platform for todays IT challenges.

* About eGenix:
eGenix is a consulting and software product company focused on
providing professional quality services and products to Python
users and developers (http://www.egenix.com/).



HOW IT WORKS

mxODBC Connect consists of two parts: a server installation which
typically runs directly on the database server and a client Python
package which is installed on the client machine that runs the Python
application.

The server part uses our high-performance database adapter mxODBC to
connect to the database server.

The client package communicates with the server part over a TCP/IP
network, optionally using SSL encryption, advanced authentication and
access controls - a feature that many database drivers fail to
deliver.

By separating the client application database interface from the
server and using mxODBC Connect, you gain several benefits:

 * high portability and flexibility
 * centralized configuration and administration
 * added security
 * automatic fail-over
 * scalability
 * lower costs

For more information, please have a look at the product page:

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



NEWS

mxODBC Connect 0.9 is a public beta release of our new mxODBC Connect
product.

If you would like to participate in the beta, please see our beta
program page:

http://www.egenix.com/products/python/mxODBCConnect/beta.html


*SPECIAL OFFER*

In order to make participation in the beta program more interesting
for our users, we will be giving out *free discount coupons* to all
participants who report back bugs in the product.



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

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

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jun 16 2008)

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


2008-07-07: EuroPython 2008, Vilnius, Lithuania20 days to go

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


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611


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

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


Decimals in python

2008-06-16 Thread arslanburney
Hello. New to using Python. Python automatically round off watver i
calculate using the floor function. How wud i make the exact value
appear?

Tried out fabs() in the math library but still confused. Cud some1
elaborate on it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question: for loop within for loop confusion

2008-06-16 Thread Paul Hankin
On Jun 16, 2:35 pm, takayuki [EMAIL PROTECTED] wrote:
 def hasnolet2(avoid):
         fin = open('animals.txt')
         for line in fin:
                 word = line.strip()

         length = len(avoid)
         x = 0
         noprint = 0

         while length -1 = x:
                 if avoid[x] in word:
                         noprint = noprint + 1
                 x = x + 1

         if noprint == 0:
                 print word

There seems to be an indendation problem (presumably the code from
length = len(avoid) onwards should be inside the loop). But apart from
that, we can try to make this more 'pythonic'.

First, python has a 'for' statement that's usually better than using
while. We use the 'range' function that produces the numbers 0, 1, ...
length - 1, and x takes the value of these in turn.

Here's the last bit of your code rewritten like this:

noprint = 0

for x in range(length):
if avoid[x] in word:
noprint += 1

if noprint == 0:
print word

But better, rather than using 'x' as an index, we can loop over
letters in avoid directly. I've changed 'noprint' to be a boolean
'should_print' too here.

should_print = True
for letter in avoid:
if letter in word:
should_print = False

if should_print:
print word

We can eliminate 'should_print' completely, by using 'break' and
'else'. A break statement in a loop causes the loop to end. If the
loop doesn't break, the 'else' code is run when the loop's over.

for letter in avoid:
if letter in word:
break
else:
print word

This is almost the same as your original code, but the 'else' is
attached to the 'for' rather that the 'if'!

Finally, in Python 2.5 you can write this:

if not any(letter in word for letter in avoid):
print word

I think this is the best solution, as it's readable and short.

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


Re: os.walk Value Error?

2008-06-16 Thread Gabriel Genellina
En Sat, 14 Jun 2008 19:06:16 -0300, [EMAIL PROTECTED] escribió:

 I'm using os.walk as follows:

 (basedir, pathnames, files) = os.walk(results, topdown=True)

 and I'm getting the error:

 ValueError: too many values to unpack

 From my googling, that means:

 This is the standard message when Python tries to unpack a tuple
 into fewer variables than are in the tuple.

 From what I can see of the examples on the python site, I'm using it
 correctly.  I have commas in my original code, and the results
 directory exists and is directly under the directory from which my
 script is run.

Look the examples more carefully again - they don't use an assignment, but 
another Python statement...

-- 
Gabriel Genellina

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


Re: Decimals in python

2008-06-16 Thread Aidan

[EMAIL PROTECTED] wrote:

Hello. New to using Python. Python automatically round off watver i
calculate using the floor function. How wud i make the exact value
appear?

Tried out fabs() in the math library but still confused. Cud some1
elaborate on it.


If you're working with integers, the result will always be an integer:

 a = 10/3
 print a
3

How ever if you add a float into the mix:

 a = 10/3.0
 print a
3.3335

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


Re: NoneType Error

2008-06-16 Thread Gabriel Genellina
En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi [EMAIL PROTECTED] escribió:

 I am using a python program on a lot of different documents and for few of
 them I will get NoneType error. I just want to skip those files and continue
 for others, I do this without a problem for
 IndexError,TypeError,ValueError,NameError :

 try:
  
 except (IndexError,TypeError,ValueError,NameError):
  

 but when I add NoneType it gives the following error:
 except (NoneType,IndexError,TypeError,ValueError,NameError):
 NameError: name 'NoneType' is not defined

 and if I do not use the NoneType then it does not go through either and
 stops the program when I get to such a file. Is there another name that
 captures this error?

NoneType is not an exception, but the type of the None object. Perhaps you're 
not interpreting correctly some error messages:

 x=None
 x()
Traceback (most recent call last):
   File stdin, line 1, in module
TypeError: 'NoneType' object is not callable

(the exception raised is a TypeError; NoneType is part of the message).

It appears that you want to catch all exceptions, just use Exception for that:
try:
   ...
except Exception:
   ...

-- 
Gabriel Genellina

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


Re: HTML FORM AND PYTHON

2008-06-16 Thread subhabrata . iisc
Hi Diez,
Thanx for the suggestion. I am checking if anything helpful I can find
there.
Regards,
Subhabrata.

Diez B. Roggisch wrote:
 [EMAIL PROTECTED] schrieb:
  Dear Members of the group,
  I have a small question, if you can help me to find the answer.
  I have one function:
  def add_string(n):
  print �Print Two strings�
  print �Print the First String�
  a1=raw_input(�PRINT THE FIRST STRING�)
  a2=raw_input(�PRINT THE SECOND STRING�)
  print �CONCATENATING THE TWO GIVEN STRINGS�
  a3=a1+a2
  print �THE RESULT IS�
  print a3
 
  Now, I have designed one HTML form which has two input fields for text
  and an output field for the result.
 
  I like to bind the python program into HTML form.
  i) Is there any way I can keep both my existing python code and HTML
  code and bind them? If any one can suggest with example.

 No. The above code works with user-interation at certain points of the
 program. That can't be (easily, and especially not with the above
 functionality) translated into the http-paradigm where each operation is
 embedded into a request/resonse-cycle, with the need for explicit or
 implicit state-keeping over these cycles.

  ii) Do I have to write the whole code in a way in python so that it
  would work the function as well as generate HTML form I am looking
  for? If any one can suggest with example.

 For this *trivial* example, I can only say: there isn't enough to be
 worth abstracting.

  iii) Is there any other way?

 Google python + webframeworks to find a bazillion discussions, opinions,
 examples.

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

All girls boys in dating available in this web sit join him

2008-06-16 Thread herlin
All girls  boys in dating available in this web sit join him
All girls  boys in dating available in this web sit join him
All girls  boys in dating available in this web sit join him
All girls  boys in dating available in this web sit join him



http://amigos.com/go/g979119-pct
--
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically restarting system calls?

2008-06-16 Thread Hrvoje Niksic
Rhamphoryncus [EMAIL PROTECTED] writes:

 You might find a way to get SA_RESTART applied, but it won't work
 right for you.  Python splits signal handlers into a top half and a
 bottom half - the bottom is in C, it's the real signal handler, and
 top is in python.  To keep things sane for the top half, it delays
 until the interpreter is in a sane state (such as between
 bytecodes).  If you used SA_RESTART the bottom half would still
 work, but the top would be delayed indefinitely until something else
 woke up the interpreter.  In other words, your window likely won't
 redraw until the user types something or you print something.

One possible way to handle this is by implementing a small signal
handler in C.  This signal handler can set the signal using
SA_RESTART, getting rid of EINTR, at least for popular syscalls.  In
the signal handler it can simply write a byte into a pipe, the other
end of which is monitored by the select() event loop.  Python,
presumably sleeping in select(), or about to do that, will immediately
notice the signal by the pipe becoming readable.
--
http://mail.python.org/mailman/listinfo/python-list


Changing Colors in gnuplot.py

2008-06-16 Thread arslanburney
Hello, Could some1 tell me how u could change the colours of the
different lines that you have plotted while using gnuplot.py. Also how
to change the background colour, line thickness etc.
Thnx
--
http://mail.python.org/mailman/listinfo/python-list


PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Armin Ronacher
Abstract


This PEP proposes an ordered dictionary as a new data structure for
the ``collections`` module, called odict in this PEP for short.  The
proposed API incorporates the experiences gained from working with
similar implementations that exist in various real-world applications
and other programming languages.


Rationale
=

In current Python versions, the widely used built-in dict type does
not specify an order for the key/value pairs stored.  This makes it
hard to use dictionaries as data storage for some specific use cases.

Some dynamic programming languages like PHP and Ruby 1.9 guarantee a
certain order on iteration.  In those languages, and existing Python
ordered-dict implementations, the ordering of items is defined by the
time of insertion of the key.  New keys are appended at the end, keys
that are overwritten and not moved.

The following example shows the behavior for simple assignments:

 d = odict()
 d['parrot'] = 'dead'
 d['penguin'] = 'exploded'
 d.items()
[('parrot', 'dead'), ('penguin', 'exploded')]

That the ordering is preserved makes an odict useful for a couple of
situations:

- XML/HTML processing libraries currently drop the ordering of
  attributes, use a list instead of a dict which makes filtering
  cumbersome, or implement their own ordered dictionary.  This affects
  ElementTree, html5lib, Genshi and many more libraries.

- There are many ordererd dict implementations in various libraries
  and applications, most of them subtly incompatible with each other.
  Furthermore, subclassing dict is a non-trivial task and many
  implementations don't override all the methods properly which can
  lead to unexpected results.

  Additionally, many ordered dicts are implemented in an inefficient
  way, making many operations more complex then they have to be.

- PEP 3115 allows metaclasses to change the mapping object used for
  the class body.  An ordered dict could be used to create ordered
  member declarations similar to C structs.  This could be useful, for
  example, for future ``ctypes`` releases as well as ORMs that define
  database tables as classes, like the one the Django framework ships.
  Django currently uses an ugly hack to restore the ordering of
  members in database models.

- Code ported from other programming languages such as PHP often
  depends on a ordered dict.  Having an implementation of an
  ordering-preserving dictionary in the standard library could ease
  the transition and improve the compatibility of different libraries.


Ordered Dict API


The ordered dict API would be mostly compatible with dict and existing
ordered dicts.  (Note: this PEP refers to the Python 2.x dictionary
API; the transfer to the 3.x API is trivial.)

The constructor and ``update()`` both accept iterables of tuples as
well as mappings like a dict does.  The ordering however is preserved
for the first case:

 d = odict([('a', 'b'), ('c', 'd')])
 d.update({'foo': 'bar'})
 d
collections.odict([('a', 'b'), ('c', 'd'), ('foo', 'bar')])

If ordered dicts are updated from regular dicts, the ordering of new
keys is of course undefined again unless ``sort()`` is called.

All iteration methods as well as ``keys()``, ``values()`` and
``items()`` return the values ordered by the the time the key-value
pair was inserted:

 d['spam'] = 'eggs'
 d.keys()
['a', 'c', 'foo', 'spam']
 d.values()
['b', 'd', 'bar', 'eggs']
 d.items()
[('a', 'b'), ('c', 'd'), ('foo', 'bar'), ('spam', 'eggs')]

New methods not available on dict:

``odict.byindex(index)``

Index-based lookup is supported by ``byindex()`` which returns
the key/value pair for an index, that is, the position of a
key in the ordered dict.  0 is the first key/value pair, -1
the last.

 d.byindex(2)
('foo', 'bar')

``odict.sort(cmp=None, key=None, reverse=False)``

Sorts the odict in place by cmp or key.  This works exactly
like ``list.sort()``, but the comparison functions are passed
a key/value tuple, not only the value.

 d = odict([(42, 1), (1, 4), (23, 7)])
 d.sort()
 d
collections.odict([(1, 4), (23, 7), (42, 1)])

``odict.reverse()``

Reverses the odict in place.

``odict.__reverse__()``

Supports reverse iteration by key.


Questions and Answers
=

What happens if an existing key is reassigned?

The key is not moved but assigned a new value in place.  This is
consistent with existing implementations and allows subclasses to
change the behavior easily::

class movingcollections.odict):
def __setitem__(self, key, value):
self.pop(key, None)
odict.__setitem__(self, key, value)

What happens if keys appear multiple times in the list passed to the
constructor?

The same as for regular dicts: The latter item overrides the
former.  This has the side-effect that the position of the 

Re: Combining music or video files?

2008-06-16 Thread Python.Arno


On 16 jun 2008, at 05:55, Jason Scheirer wrote:


On Jun 15, 7:53 pm, John Salerno [EMAIL PROTECTED] wrote:

Before I try this and destroy my computer :) I just wanted to see if
this would even work at all. Is it possible to read a binary file  
such
as an mp3 or an avi, put its contents into a new file, then read  
another
such file and append its contents to this same new file as well,  
thereby

making, for example, a single long video instead of two smaller ones?

Thanks.


This works with basic mpeg videos, but pretty much nothing else.
You're going to need some video editing software.


you can't just edit mpeg (including mp3)...
mpeg is a stream. it sets a key frame for the first frame
followed by motion vectors from the changes from that frame
until the next keyframe.
If you cut in the middle of the vectors the keyframe is lost
and the vector frames don;t make any sense anymore.

avi is not a video codec, it's a container like quicktime.
so it depends...

I come from a Mac background and use quicktime a lot.
there are some basic editing features that quicktime can do.
And Apple has a nice quicktime python module in OSX.
I bet there's something for windows too...

best thing to do is convert the video o a framesequence and
the audio to an uncompressed format like wav or aiff
then combine in quicktime or something in windows

cheers,
Arno




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


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Michele Simionato
On Jun 16, 10:37 am, Armin Ronacher [EMAIL PROTECTED]
wrote:
 Abstract
 

 This PEP proposes an ordered dictionary as a new data structure for
 the ``collections`` module, called odict in this PEP for short.  The
 proposed API incorporates the experiences gained from working with
 similar implementations that exist in various real-world applications
 and other programming languages.

+1, I have been waiting for an odict in the library for at least 5
years.


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


Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread Diez B. Roggisch
Diez B. Roggisch wrote:

 George Sakkis schrieb:
 I have a situation where one class can be customized with several
 orthogonal options. Currently this is implemented with (multiple)
 inheritance but this leads to combinatorial explosion of subclasses as
 more orthogonal features are added. Naturally, the decorator pattern
 [1] comes to mind (not to be confused with the the Python meaning of
 the term decorator).
 
 However, there is a twist. In the standard decorator pattern, the
 decorator accepts the object to be decorated and adds extra
 functionality or modifies the object's behavior by overriding one or
 more methods. It does not affect how the object is created, it takes
 it as is. My multiple inheritance classes though play a double role:
 not only they override one or more regular methods, but they may
 override __init__ as well. Here's a toy example:
 
 class Joinable(object):
 def __init__(self, words):
 self.__words = list(words)
 def join(self, delim=','):
 return delim.join(self.__words)
 
 class Sorted(Joinable):
 def __init__(self, words):
 super(Sorted,self).__init__(sorted(words))
 def join(self, delim=','):
 return '[Sorted] %s' % super(Sorted,self).join(delim)
 
 class Reversed(Joinable):
 def __init__(self, words):
 super(Reversed,self).__init__(reversed(words))
 def join(self, delim=','):
 return '[Reversed] %s' % super(Reversed,self).join(delim)
 
 class SortedReversed(Sorted, Reversed):
 pass
 
 class ReversedSorted(Reversed, Sorted):
 pass
 
 if __name__ == '__main__':
 words = 'this is a test'.split()
 print SortedReversed(words).join()
 print ReversedSorted(words).join()
 
 
 So I'm wondering, is the decorator pattern applicable here ? If yes,
 how ? If not, is there another way to convert inheritance to
 delegation ?
 
 Factory - and dynamic subclassing, as shown here:
 
 import random
 
 class A(object):
  pass
 
 class B(object):
  pass
 
 
 def create_instance():
  superclasses = tuple(random.sample([A, B], random.randint(1, 2)))
  class BaseCombiner(type):
 
  def __new__(mcs, name, bases, d):
  bases = superclasses + bases
  return type(name, bases, d)
 
  class Foo(object):
  __metaclass__ = BaseCombiner
  return Foo()
 
 for _ in xrange(10):
  f = create_instance()
  print f.__class__.__bases__

Right now I see of course that I could have spared myself the whole
__metaclass__-business and directly used type()... Oh well, but at least it
worked :)

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


Re: Best way to make a number of tests against an object('s attributes) with absence of switch statement?

2008-06-16 Thread Bruno Desthuilliers

Phillip B Oldham a écrit :

What would be the optimal/pythonic way to subject an object to a
number of tests (based on the object's attributes) and redirect
program flow?

Say I had the following:

pets[0] = {'name': 'fluffy', 'species': 'cat', 'size': 'small'}
pets[1] = {'name': 'bruno', 'species': 'snake', 'size': 'small'}
pets[2] = {'name': 'rex', 'species': 'dog', 'size': 'large'}

What I'd like to do is loop through 'pets', and test each object. Some
of the tests I'd like to perform are:

Is the size 'small' and species not 'dog'?
Is the species 'cat' and name 'fluffy'?
Is the species not 'dog' or 'cat'?

In PHP I'd use a switch statement similar to the following:

foreach( $pets as $pet) {
switch(true) {
case ( $pet['size'] === 'small'  $pet['species'] !== 'dog' ):
// do something
break;
// etc...
}
}

Now, I understand from a bit of googling that python doesn't have a
switch statement, and because of this people rely on python's
polymorphism.


You could also put it the other way round : Python doesn't have a switch 
statement because peoples use polymorphism !-)


(nb : not that my reversed statement is in any way more true than 
yours - but the fact is that procedural switch statement vs OO 
polymorphic dispatch is not such a new topic...)



Thats great, but I've yet to come across a decent
example which make a click.

Any thoughts on how to proceed?


The braindead canonical OO solution would be to make a specific class 
for each species each implementing it's own version of do_something(). 
The problem is that it would only dispatch on species, not other 
attributes (size etc). Which is a inherent limitation of the canonical 
OO type-based single dispatch mechanism.


A more elaborate canonical OO solution would be to use the visitor 
pattern to overcome the single dispatch limitation.


A yet more elaborate (but way less canonical) solution is to use 
predicate-based dispatch (cf Philip Eby's work).


Anyway, and while each dispatch mechanism (from basic branching to 
complex predicate-based systems) has it's pros and cons, I'd first think 
twice (or more) about whether my current dispatch problem has some 
relative stability wrt/ the domain - IOW, it's structurally part of the 
domain and won't change anytime soon - or if it's one of those ad-hoc 
short-lived illogical business rule that is potentially subject to 
unpredictable change any other day. Because the appropriate solution 
really depends on this kind of considerations.


Now wrt/ your concrete example: truth is that, while expressed as a 
switch statement, it's in fact really a if/elif/.../, since the 
condition is not a constant (so you don't gain any performance gain from 
using a switch). So the simplest translation in Python is to use an 
if/elif/...



for pet in pets:
  if pet['size'] == 'small' and pet['species'] !== 'dog':
 // do something
  elif (other complex condition):
 // etc

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


Re: Hard to understand 'eval'

2008-06-16 Thread Bruno Desthuilliers

TheSaint a écrit :

On 04:08, domenica 15 giugno 2008 [EMAIL PROTECTED] wrote:


what's wrong with getattr(cp, nn) ?


The learning curve to get into these programming ways.
Does gettattr run the snippet passed in?


Nope, it just does what the name implies.


Considering that nn is a name of function, which will be called and (cfl,
value) are the parameters to passed to that function.


Everything in Python's an object (at least anything you can bind to a 
name), including functions and methods. Once you have a callable object, 
you just have to apply the call operator (parens) to call it. In your 
case, that would be:


func = getattr(cc, nn, None)
if callable(func):
  result = func(cfl, value)
else:
  do_whatever_appropriate_here()


I'll spend some bit on getattr use.


Would be wise IMHO.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hard to understand 'eval'

2008-06-16 Thread Bruno Desthuilliers

TheSaint a écrit :

On 01:15, lunedì 16 giugno 2008 Calvin Spealman wrote:


such as getattr(obj,
methname)(a, b, c). Does this make sense?


This is big enlightenment :) Thank you! :)

I found problem with eval() when it comes to pass quoted strings.
I circumvent that by encapsulating the strings in variable or tuple.
The principle is to have a name which will refers a function somewhere in the
program and to call that function, plus additional data passed in.

In other word I'd expect something:

function_list= ['add' ,'paint', 'read']
for func in function_list:
  func(*data)


Can't work - function_list is a list of strings, not a list of 
functions. If the functions you intend to call are already bound to 
names in the current scope, you don't even need any extra lookup 
indirection:


def add(*args):
  # code here

from some_module import paint

obj = SomeClass()
read = obj.read

functions = [add, paint, read]
args = [1, 2]
for func in functions:
func(*args)



I tried getattr,


getattr is useful when you only have the name of the 
function/method/whatever attribute as a string. And a target object 
(hint: modules are objects too) of course - if the name lives either in 
the global or local namespace, you can access it by name using the dicts 
returned by resp. the globals() and locals() functions.


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

Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Ben Finney
Armin Ronacher [EMAIL PROTECTED] writes:

 This PEP proposes an ordered dictionary as a new data structure for
 the ``collections`` module, called odict in this PEP for short.

A welcome addition.

Since we're not proposing a built-in type, could we choose a name that
is more explicit, and consistent with the types in 'collections'
already. I'd prefer one of the following:

  collections.ordereddict
  collections.ordered_dict


Other (minor) comments:

 The key is not moved but assigned a new value in place.  This is
 consistent with existing implementations and allows subclasses to
 change the behavior easily::
 
 class movingcollections.odict):

Something is missing in the above line of code. It's invalid as-is,
but I don't know which of the many possible replacements is intended.

 Why is there no ``odict.insert()``?

Thank you for this design decision; I agree entirely that the correct
solution is to resequence and create a new ordered dict from the
result.

 A poorly performing example implementation of the odict written in
 Python is available:
 
 `odict.py http://dev.pocoo.org/hg/sandbox/raw-file/tip/
 odict.py`_

This seems to be a victim of errant line-breaking, resulting in the
wrong URL.

-- 
 \“The reason we come up with new versions is not to fix bugs. |
  `\ It's absolutely not.” —Bill Gates, 1995-10-23 |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: NoneType Error

2008-06-16 Thread Bruno Desthuilliers

Gabriel Genellina a écrit :

En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi [EMAIL PROTECTED] escribió:


(snip)


It appears that you want to catch all exceptions, just use Exception for that:
try:
   ...
except Exception:
   ...



Hem... That's definitively *not* an a good advice here IMHO. A catch-all 
may be useful near a program's 'top-level' to handle any other unhandled 
exception in a more user-friendly way (ie : log the error, warns whoever 
is in charge, try to cleanly dispose of resources / data / whatever so 
we don't break anything, and display a nice and visible error message to 
the user), but anywhere else you really want to know *exactly* which 
exception(s) you're expecting to handle here and let the other propagate.

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


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Wolfgang Grafen

Armin Ronacher schrieb:

Other implementations of ordered dicts in various Python projects or
standalone libraries, that inspired the API proposed here, are:

- `odict in Babel`_
- `OrderedDict in Django`_
- `The odict module`_
- `ordereddict`_ (a C implementation of the odict module)
- `StableDict`_
- `Armin Rigo's OrderedDict`_


.. _odict in Babel: 
http://babel.edgewall.org/browser/trunk/babel/util.py?rev=374#L178
.. _OrderedDict in Django:
   
http://code.djangoproject.com/browser/django/trunk/django/utils/datastructures.py?rev=7140#L53
.. _The odict module: http://www.voidspace.org.uk/python/odict.html
.. _ordereddict: http://www.xs4all.nl/~anthon/Python/ordereddict/
.. _StableDict: http://pypi.python.org/pypi/StableDict/0.2
.. _Armin Rigo's OrderedDict: 
http://codespeak.net/svn/user/arigo/hack/pyfuse/OrderedDict.py
I want add to this list my seqdict package, maybe the first 
implementation of an ordered dict in Python?

http://home.arcor.de/wolfgang.grafen/Python/Modules/Modules.html

I have never seen a real world dictionary which wasn't in order, so I 
ever felt the Python dictionary was not complete. I support the idea of 
an ordered dictionary in Python.


Best regards

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


Re: Checking each item in m.group()?

2008-06-16 Thread Gilles Ganault
On Sun, 15 Jun 2008 18:15:38 -0700, Dennis Lee Bieber
[EMAIL PROTECTED] wrote:
   I don't know quite what the reason for the sql = sql + ... is -- if
you are trying to package more than one discrete statement into a single
query you should be advised that not all adapters/DBMS support that
function (I think one uses executescript() to signify multiple
distinct statements.

The script will go through about 3,000 lines of text, so I wanted to
create a transaction with BEGIN/COMMIT. It seems like APSW (the
simpler version of PySQLite) doesn't do transactions silently.

A decent adapter should convert Python's None object into a proper DBMS
Null. The adapter is also responsible for doing any needed quoting or
escaping of the data supplied, hence no quoting of the placeholders!

Thanks for the tip. However, after looking at the code you gave, I'm
getting an error when running cur.execute(), so it is only ran once
and the program exits:

=
import sys, re, apsw, os

connection=apsw.Connection(test.sqlite)
cursor=connection.cursor()

textlines = []
textlines.append(123\titem1\titem2\titem3\titem4\t345\titem6)
textlines.append(123\titem1\t\titem3\titem4\t345\titem6)

p = re.compile(^(\d+)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(\d+)\t(.+?)$)
for line in textlines:
m = p.search(line)
if m:
sql = 'INSERT INTO test (col1,col2,col3,col4,col5,col6,col7)
VALUES (?,?,?,?,?,?,?);'


cursor.execute(sql, tuple((c, None)[c == ] for c in m.groups()))
  File apsw.c, line 3518, in resetcursor
apsw.ConstraintError: ConstraintError: not an error
apsw.ConnectionNotClosedError: apsw.Connection on test.sqlite.  The
destructor has been called, but you haven't closed the connection. All
connections must be explicitly closed.  The SQLite database object is
being leaked.
 
cursor.execute(sql, tuple((c, None)[c == ] for c in 
m.groups()))

connection.commit()
connection.close(True)

=

I read the online sample for APSW, but didn't find what it could be.
Any idea?

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


Re: marshal.dumps quadratic growth and marshal.dump not allowing file-like objects

2008-06-16 Thread Raymond Hettinger
On Jun 15, 8:08 am, [EMAIL PROTECTED] wrote:
 Indeed. I (the OP) am using a production release which has the 1k
 linear growth.
 I am seeing the problems with ~5MB and ~10MB sizes.
 Apparently this will be improved greatly in Python 2.6, at least up to
 the 32MB limit.

I've just fixed this for Py2.5.3 and Py2.6.  No more quadratic
behavior.


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


ANN: eGenix mxODBC Connect Database Interface for Python 0.9.1 (beta)

2008-06-16 Thread eGenix Team: M.-A. Lemburg



ANNOUNCING
eGenix.com mxODBC Connect

  Database Interface for Python

   Version 0.9.1 (beta)


  Our new client-server product for connecting Python applications
 to relational databases - on all major platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Connect-0.9.1-beta.html



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.  This makes
mxODBC Connect the ideal basis for writing cross-platform database
programs and utilities in Python.

mxODBC Connect extends our eGenix mx Python Extension series with a
new client-server based product, that removes the need to install and
configure ODBC drivers on the client side. This greatly simplifies
setup and configuration of database driven client applications, while
at the same time making the network communication between client and
database server more efficient and more secure.

* About Python:
Python is an object-oriented Open Source programming language which
runs on all modern platforms (http://www.python.org/). By integrating
ease-of-use, clarity in coding, enterprise application connectivity
and rapid application design, Python establishes an ideal programming
platform for todays IT challenges.

* About eGenix:
eGenix is a consulting and software product company focused on
providing professional quality services and products to Python
users and developers (http://www.egenix.com/).



HOW IT WORKS

mxODBC Connect consists of two parts: a server installation which
typically runs directly on the database server and a client Python
package which is installed on the client machine that runs the Python
application.

The server part uses our high-performance database adapter mxODBC to
connect to the database server.

The client package communicates with the server part over a TCP/IP
network, optionally using SSL encryption, advanced authentication and
access controls - a feature that many database drivers fail to
deliver.

By separating the client application database interface from the
server and using mxODBC Connect, you gain several benefits:

 * high portability and flexibility
 * centralized configuration and administration
 * added security
 * automatic fail-over
 * scalability
 * lower costs

For more information, please have a look at the product page:

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



NEWS

mxODBC Connect 0.9 is a public beta release of our new mxODBC Connect
product.

If you would like to participate in the beta, please see our beta
program page:

http://www.egenix.com/products/python/mxODBCConnect/beta.html


*SPECIAL OFFER*

In order to make participation in the beta program more interesting
for our users, we will be giving out *free discount coupons* to all
participants who report back bugs in the product.



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

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

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jun 16 2008)

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


2008-07-07: EuroPython 2008, Vilnius, Lithuania20 days to go

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


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611


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


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread bearophileHUGS
Oh, very good, better late than never.
This is my pure Python version, it performs get, set and del
operations too in O(1):
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498195
Working with C such data structure becomes much faster, because it can
use true pointers.

Then another data structure that may be named SortedDict can be
created, that keeps items in their natural order (instead of the
insertion order).

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


String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Bart Kastermans
Summary: can't verify big O claim, how to properly time this?

On Jun 15, 2:34 pm, Terry Reedy [EMAIL PROTECTED] wrote:
 Bart Kastermans [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]
 |I wrote a binary search tree in python, explaining as I was doing it
 | how and why I did it.  I am very interested in receiving comments on
 | the code, process, and anything else that will improve my coding or
 | writing.
 |
 | I wrote this all up in my blog at:
 |
 |http://kasterma.wordpress.com/2008/06/15/implementing-a-binary-search...
 |
 | The code of the class has been copied below, but the description of
 | the process (mostly an attempt at approaching test driving development
 | for as far as I understand the term) has not been copied.
 |
 | Any and all comments are appreciated.
 |
 | Best,
 | Bart
 |
 | *** python code 
 |
 |
 | import re
 |
 | class BSTree:
 |def __init__ (self, value = None):
 |self.value = value
 |self.left = None
 |self.right = None

 There are two possible approaches.
 1. Define 1 tree class that is also used for subtrees -- what you did.
Complication: self.value of root node can be none, so you constantly
 have to check self.value for None even though only possible for root node.
 2. Define tree class and node class.  This had other complications, but
 removes that above and makes str easier.  tree.str = '(' str(rootnode) ')'
 and node.str= self.value '(' str(self.left) ')' '(' str(self.right) ')'.

 If use '' instead of None, no conditionals are needed.  (This might apply
 partly to your version as well.)  Or define class NullTree with a singleton
 instance with no attributes and a str method returning '' and an inOrder
 method yielding nothing.  This would also eliminate the condifionals in the
 inOrder method.  Not sure what is best.  With a good test suite, it is easy
 to make sure alternative implementations 'work' before testing for speed.

Thanks for the idea.  I would expect the separation to lead to
somewhat more
code, but all the checking the root code would be separated out in
the
tree class.  The node class would be very smooth.  I'll try this when
I have
some time (today I spend my alloted programming time on what is
below).

(also the comment about inOrder returning a generator was because I
tried to
figure it out, failed, and then got enough by doing it without yield.
I forgot
to bring my comment in line with my code.  A generator
would certainly be nicer, and I'll work at understanding your
suggestion for
it.)


 |def __str__ (self):

 string appending is an O(n**2) operations.  The usual idiom, applied here,
 would be slist = ['('], slist.append(str(self.value)),  return
 ''.join(slist).  In other words, collect list of pieces and join at end.

This is interesting.  I had never attempted to verify a big O
statement
before, and decided that it would be worth trying.  So I wrote some
code to
collect data, and I can't find that it goes quadratic.  I have the
graph
at

http://kasterma.wordpress.com/2008/06/16/complexity-of-string-concatenation/

It looks piecewise linear to me.

The code I used to collect the data is as follows:

*

import time

NUMBER = 100   # number of strings to concatenate at given length
JUMP = 500 # jump (and start length) of length of strings
END = 11# longest length string considered

def randomString (length):
 returns a random string of letters from {a,b,c,d} of length


string = 

for i in range (0,length):
string += choice (abcd)

return string

def randomStrings (number, length):
 returns an array of number random strings all of length 

array = []

for i in range (0, number):
array.append (randomString (length))

return array

TimingData = []

for length in range (JUMP, END, JUMP):
array1 = randomStrings (NUMBER, length)
array2 = randomStrings (NUMBER, length)

starttime = time.clock ()
for i in range (0, NUMBER):
string = array1 [i] + array2 [i]
endtime = time.clock ()
print length, length, done

TimingData.append ([length, 1000* (endtime-starttime)])
# to get a better looking graph multiply by 1000

sagefile = open ('stringConcatGraph.sage', w)
sagefile.write (points = + str (TimingData) + \n)
sagefile.write (graph = line (points)\n)
sagefile.write (graph.show ()\n)
sagefile.close ()

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


help in soaplib

2008-06-16 Thread sukadeb acharya
HI,
  I am trying to use the attachment object in soaplib. I am sending an
attachment object and some other arguments and also receving an attachment
object. So times I am able to receive the output image SVG file in my client
side. But sometimes I am not. I am getting the following error message:
-
Traceback (most recent call last):
  File bifaclient.py, line 12, in module

received=client.BiFa_analyser(file_to_send,[Mm]ouse,0.1,.,'all',False,True)
  File
/Volumes/RAID1/xraid/Users/sukadeb/local/lib/python2.5/site-packages/soaplib-0.7.2dev_r27-py2.5.egg/soaplib/client.py,
line 161, in __call__
payload, headers = from_soap(data)
  File
/Volumes/RAID1/xraid/Users/sukadeb/local/lib/python2.5/site-packages/soaplib-0.7.2dev_r27-py2.5.egg/soaplib/soap.py,
line 89, in from_soap
root, xmlids = ElementTree.XMLID(xml_string)
  File string, line 89, in XMLID
  File string, line 86, in XML
SyntaxError: no element found: line 1067, column 0


 Due to firewall problems my server and client are in the same machine but
in different directories.

Kindly Help,
Thank you in advance,
Sukadeb.
--
http://mail.python.org/mailman/listinfo/python-list

Context manager for files vs garbage collection

2008-06-16 Thread Floris Bruynooghe
Hi

I was wondering when it was worthwil to use context managers for
file.  Consider this example:

def foo():
t = False
for line in file('/tmp/foo'):
if line.startswith('bar'):
t = True
break
return t

What would the benefit of using a context manager be here, if any?
E.g.:

def foo():
t = False
with file('/tmp/foo') as f:
for line in f:
if line.startswith('bar'):
t = True
break
return t

Personally I can't really see why the second case would be much
better, I've got used to just relying on the garbage collector... :-)
But what is the use case of a file as a context manager then?  Is it
only useful if your file object is large and will stay in scope for a
long time?

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


Python GC does not work as it should be

2008-06-16 Thread Jaimy Azle
See this piece of code:

/* API to invoke gc.collect() from C */
Py_ssize_t
PyGC_Collect(void)
{
 Py_ssize_t n;

 if (collecting)
  n = 0; /* already collecting, don't do anything */
 else {
  collecting = 1;
  n = collect(NUM_GENERATIONS - 1);
  collecting = 0;
 }
 return n;
}

If a system exception raised when executing collect(xxx), collecting state 
variable would never be reset and python GC will not works forever until the 
application restarted. Perhaps it is a rare situation on normal usage, i 
mean if 100% code written in python. I use python as an embedded engine on a 
multithreaded server handling business process script which written in 
python. Though at last i found my code that causing it and fixed, i still 
think those code still has a potential problem on a long running process (as 
server side scripting language). My workaround limited to implementation 
with MSVC, I wrap those code in an exception trapper, and force to reset 
collecting variable.

Salam,

-Jaimy.


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


Re: Python GC does not work as it should be

2008-06-16 Thread Jean-Paul Calderone

On Mon, 16 Jun 2008 17:51:00 +0700, Jaimy Azle [EMAIL PROTECTED] wrote:

See this piece of code:

/* API to invoke gc.collect() from C */
Py_ssize_t
PyGC_Collect(void)
{
Py_ssize_t n;

if (collecting)
 n = 0; /* already collecting, don't do anything */
else {
 collecting = 1;
 n = collect(NUM_GENERATIONS - 1);
 collecting = 0;
}
return n;
}

If a system exception raised when executing collect(xxx), collecting state
variable would never be reset and python GC will not works forever until the
application restarted.


A system exception?  What's that?  C doesn't have exceptions.

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


Re: Python GC does not work as it should be

2008-06-16 Thread Jaimy Azle
Jean-Paul Calderone wrote:


 A system exception?  What's that?  C doesn't have exceptions.


How could I determine it? I dont know GCC implementation, and others, but C 
on MSVC does have it. My application were not written in C, an exception 
raised was something like access violation at address  on module 
python25.dll, and MSVC debugger shows collecting state were not reset (1), 
that is why GC would never happen.

Salam,

-Jaimy.



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


Showing a point in Gnuploy.py

2008-06-16 Thread arslanburney
Hello. Could some1 tell me how i could display a specific point in
gnuplot.py. Supposingly if i have a point of intersection (2,3). How
can i show this on the graph? As in how can i write near the point of
intersection the value :(2,3).
Thnx
--
http://mail.python.org/mailman/listinfo/python-list


Re: Notify of change to list

2008-06-16 Thread Alan J. Salmoni
Paul - thank you very much for your help, it was much appreciated. I
thought that this was the kind of thing I had to do.

I also messed around with properties to try and solve this problem,
but noticed a similar thing (ie, that changing a mutable attribute's
element is different to rebinding it): when a propertied attribute
is rebound, the set method is called as expected. However, when
setting an element of a mutable like a list, the get method is called
and the set is not. This seems to be a bit of a gotcha. I'm sure that
calling the get method is justified in the terms of Python internals,
but as a user it seems a little counter-intuitive. Without being an
expert on language design, my first thought was that changing an
element was a set operation. Here's a toy:

class tobj(object):
def __init__(self):
self._x = [0,1,2,3,4,5,6]

def setx(self, x):
print At setx
self._x = x

def getx(self):
print At getx
return self._x

d = property(getx, setx)

a = tobj()
print setting one element only
a.d[1] = 3
print rebinding the attribute
a.d = 99

which comes up with:

setting one element only
At getx
rebinding the attribute
At setx

Does anyone know why it works like this? I would guess that to set
one element, the attribute needs to be retrieved which means the get
method is called. I also guess that only rebinding calls the set
method which is why it isn't called here.

Alan

On Jun 13, 11:19 am, Paul Hankin [EMAIL PROTECTED] wrote:
 On Jun 13, 12:00 pm, Alan J.Salmoni [EMAIL PROTECTED] wrote:

  My question is how can my program be notified of a change to a class
  attribute that is a list?

 You can't. But you can replace lists inside your class with a list
 that notifies changes.

 Something like this:

 class NotifyingList(list):
 def __setitem__(self, i, v):
 print 'setting', i, 'to', v
 list.__setitem__(self, i, v)

 [[You'll likely need to redefine __setslice__, __delitem__,
 __delslice__, append and extend as well]].

  x = NotifyingList([1, 2, 3])
  x[1] = 4
 setting 1 to 4
  x

 [1, 4, 3]

 If users of your class are allowed to replace attributes with their
 own lists, you'll have to catch these and convert to NotifyingLists;
 and it may be somewhat messy.

 I hope this is useful to you.

 --
 Paul Hankin

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


SPAM

2008-06-16 Thread Dantheman
SPAM
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python GC does not work as it should be

2008-06-16 Thread Jean-Paul Calderone

On Mon, 16 Jun 2008 18:11:24 +0700, Jaimy Azle [EMAIL PROTECTED] wrote:

Jean-Paul Calderone wrote:



A system exception?  What's that?  C doesn't have exceptions.



How could I determine it? I dont know GCC implementation, and others, but C
on MSVC does have it. My application were not written in C, an exception
raised was something like access violation at address  on module
python25.dll, and MSVC debugger shows collecting state were not reset (1),
that is why GC would never happen.


Ah, one of those.  Thanks for the clarification.  That basically means your
program was supposed to crash.  Instead, since you had visual studio around
it handled the violation by popping up a dialog and giving you the choice to
continue execution, which I guess you did.

There's plenty of things other than that one static variable that can get
messed up in this scenario.  The access violation could easily come along
with random memory corruption.  Fixing just the GC to handle this doesn't
mean your program will be able to keep running correctly.  It's difficult
or impossible to know what else has been put into an inconsistent state.

The real fix is probably to track down what is causing the access violation.
Once you fix that, the GC shouldn't need to be changed to account for this
possibility, and you'll stop getting dialogs popping up from your app. :)

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


sorted or .sort() ?

2008-06-16 Thread Peter Bengtsson
My poor understanding is that the difference between `sorted(somelist,
key=lambda x:...)` and `somelist.sort(lambda x,y...)` is that one
returns a new list and the other sorts in-place.

Does that mean that .sort() is more efficient and should be favored
when you can (i.e. when you don't mind changing the listish object)?
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Jeroen Ruigrok van der Werven
-On [20080616 10:41], Armin Ronacher ([EMAIL PROTECTED]) wrote:
This PEP proposes an ordered dictionary as a new data structure for
the ``collections`` module, called odict in this PEP for short.

I fully support adding this. In my work I have had to create this datatype a
few times already.

The suggested design choices seem logical to me.

+1

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Of all that is to come, the Dream has just begun...
--
http://mail.python.org/mailman/listinfo/python-list

Re: sorted or .sort() ?

2008-06-16 Thread Ben Finney
Peter Bengtsson [EMAIL PROTECTED] writes:

 My poor understanding is that the difference between `sorted(somelist,
 key=lambda x:...)` and `somelist.sort(lambda x,y...)` is that one
 returns a new list and the other sorts in-place.

Yes.

 Does that mean that .sort() is more efficient and should be favored
 when you can (i.e. when you don't mind changing the listish object)?

No, it means you should choose the version that expresses what you
actually want to do.

Efficiency of the programmers — including the unknown number of
programmers who will have to read the code after you write it — is in
many cases a much more important criterion than efficiency of the CPU.
People's time continues to be much more expensive than computer time,
after all.

-- 
 \   Are you pondering what I'm pondering? Umm, I think so, |
  `\Brain, but what if the chicken won't wear the nylons?  -- |
_o__)_Pinky and The Brain_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: bpython - fancy Python shell

2008-06-16 Thread Wolfgang Grafen

I couldn't get it work on Solaris (modified some lines for Python2.3).
One reason was that I had to download pyreadline separately
- I did than but now pyreadline requires either ironpython or
  a windows installation. Something is going wrong...

Best regards

Wolfgang

Bob Farrell schrieb:

I released this a while ago but did some work recently to fix some bugs
so I thought I may as well post it here. To quickly summarise:
In-line syntax highlighting
Auto complete with suggestions as you type
Pastebin stuff, save to file
Rewind feature to jump back a line if you mess up (don't ask how it
works, please ;)

You can get it here:
http://www.noiseforfree.com/bpython/

There's info about git repos and what have you there, and apparently
it's also in some real distro repos, but I don't know the details.

Oh, and you'll need pygments and pyparsing, and it doesn't work on
Windows (heard good reports about it working fine on a Mac though).

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


Zipping python modules

2008-06-16 Thread Brian Vanderburg II
I've installed Python 2.5 on MSW and it works.  I'm preparing it to run 
from a thumb drive so I can run applications by dropping them onto the 
python.exe or from command line/etc.  It works but the size is quite 
large.  I've compressed most of the executables with UPX even the dlls 
under site-packages, but is there a way I could compress the top-level 
'lib' directory into a python.zip instead so save some space, and do I 
need the 'test' directory (which is about 10MB itself)?


Brian Vanderburg II


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


Re: newbie question: for loop within for loop confusion

2008-06-16 Thread John Salerno
takayuki [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 John: There were two inchworms because c is in inchworm so it
 shouldn't print.  Thanks for your detailed description of the for
 loop.

lol, I even sat there looking at the word and said to myself ok, it doesn't 
contain any of the four letters  :) 


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


Re: newbie question: for loop within for loop confusion

2008-06-16 Thread John Salerno
takayuki [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 fin = open('animals.txt')
 for line in fin:

You can write this as:

for line in open('animals.txt'):
#do stuff

Of course, you can't explicitly close the file this way, but that probably 
doesn't matter. Another way, I think, is to wrap the for loops in this:

with open('animals.txt') as file:
#for loop stuff here 


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


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Calvin Spealman

This gets my +1, for what its worth.

I don't really see a good reason not to include the insert() method,  
however. I don't see that it would complicate things much, if at all.


 d = odict([('a', 42), ('b', 23)])
 d.insert(1, ('c', 19))
 d
collections.odict([('a', 42), ('c', 19), ('b', 23)])

On Jun 16, 2008, at 4:37 AM, Armin Ronacher wrote:


Abstract


This PEP proposes an ordered dictionary as a new data structure for
the ``collections`` module, called odict in this PEP for short.  The
proposed API incorporates the experiences gained from working with
similar implementations that exist in various real-world applications
and other programming languages.


Rationale
=

In current Python versions, the widely used built-in dict type does
not specify an order for the key/value pairs stored.  This makes it
hard to use dictionaries as data storage for some specific use cases.

Some dynamic programming languages like PHP and Ruby 1.9 guarantee a
certain order on iteration.  In those languages, and existing Python
ordered-dict implementations, the ordering of items is defined by the
time of insertion of the key.  New keys are appended at the end, keys
that are overwritten and not moved.

The following example shows the behavior for simple assignments:


d = odict()
d['parrot'] = 'dead'
d['penguin'] = 'exploded'
d.items()

[('parrot', 'dead'), ('penguin', 'exploded')]

That the ordering is preserved makes an odict useful for a couple of
situations:

- XML/HTML processing libraries currently drop the ordering of
  attributes, use a list instead of a dict which makes filtering
  cumbersome, or implement their own ordered dictionary.  This affects
  ElementTree, html5lib, Genshi and many more libraries.

- There are many ordererd dict implementations in various libraries
  and applications, most of them subtly incompatible with each other.
  Furthermore, subclassing dict is a non-trivial task and many
  implementations don't override all the methods properly which can
  lead to unexpected results.

  Additionally, many ordered dicts are implemented in an inefficient
  way, making many operations more complex then they have to be.

- PEP 3115 allows metaclasses to change the mapping object used for
  the class body.  An ordered dict could be used to create ordered
  member declarations similar to C structs.  This could be useful, for
  example, for future ``ctypes`` releases as well as ORMs that define
  database tables as classes, like the one the Django framework ships.
  Django currently uses an ugly hack to restore the ordering of
  members in database models.

- Code ported from other programming languages such as PHP often
  depends on a ordered dict.  Having an implementation of an
  ordering-preserving dictionary in the standard library could ease
  the transition and improve the compatibility of different libraries.


Ordered Dict API


The ordered dict API would be mostly compatible with dict and existing
ordered dicts.  (Note: this PEP refers to the Python 2.x dictionary
API; the transfer to the 3.x API is trivial.)

The constructor and ``update()`` both accept iterables of tuples as
well as mappings like a dict does.  The ordering however is preserved
for the first case:


d = odict([('a', 'b'), ('c', 'd')])
d.update({'foo': 'bar'})
d

collections.odict([('a', 'b'), ('c', 'd'), ('foo', 'bar')])

If ordered dicts are updated from regular dicts, the ordering of new
keys is of course undefined again unless ``sort()`` is called.

All iteration methods as well as ``keys()``, ``values()`` and
``items()`` return the values ordered by the the time the key-value
pair was inserted:


d['spam'] = 'eggs'
d.keys()

['a', 'c', 'foo', 'spam']

d.values()

['b', 'd', 'bar', 'eggs']

d.items()

[('a', 'b'), ('c', 'd'), ('foo', 'bar'), ('spam', 'eggs')]

New methods not available on dict:

``odict.byindex(index)``

Index-based lookup is supported by ``byindex()`` which returns
the key/value pair for an index, that is, the position of a
key in the ordered dict.  0 is the first key/value pair, -1
the last.


d.byindex(2)

('foo', 'bar')

``odict.sort(cmp=None, key=None, reverse=False)``

Sorts the odict in place by cmp or key.  This works exactly
like ``list.sort()``, but the comparison functions are passed
a key/value tuple, not only the value.


d = odict([(42, 1), (1, 4), (23, 7)])
d.sort()
d

collections.odict([(1, 4), (23, 7), (42, 1)])

``odict.reverse()``

Reverses the odict in place.

``odict.__reverse__()``

Supports reverse iteration by key.


Questions and Answers
=

What happens if an existing key is reassigned?

The key is not moved but assigned a new value in place.  This is
consistent with existing implementations and allows subclasses to
change the behavior easily::

class movingcollections.odict):
def 

Re: Context manager for files vs garbage collection

2008-06-16 Thread Bruno Desthuilliers

Floris Bruynooghe a écrit :

Hi

I was wondering when it was worthwil to use context managers for
file.  Consider this example:

def foo():
t = False
for line in file('/tmp/foo'):
if line.startswith('bar'):
t = True
break
return t

What would the benefit of using a context manager be here, if any?
E.g.:

def foo():
t = False
with file('/tmp/foo') as f:
for line in f:
if line.startswith('bar'):
t = True
break
return t

Personally I can't really see why the second case would be much
better, I've got used to just relying on the garbage collector... :-)


IIRC (please someone correct me if I'm wrong), proper release of file 
resources as soon as the file object gets out of scope is not garanteed 
in the language spec and is implementation dependant.


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


Re: Combining music or video files?

2008-06-16 Thread John Salerno
Dennis Lee Bieber [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On Sun, 15 Jun 2008 22:53:19 -0400, John Salerno
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:
 Even the simplest format - WAV, which is normally uncompressed
 audio samples, is wrapped in layers of informational packets.

 snip other stuff!!!

Yikes! Then what I'm reading from your post (and others) is no, I can't do 
it my way. ;) It *did* seem a little too easy, after all! 


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


Re: Iterate creating variables?

2008-06-16 Thread Hyuga
On Jun 13, 11:34 am, Reedick, Andrew [EMAIL PROTECTED] wrote:
  -Original Message-
  From: [EMAIL PROTECTED] [mailto:python-
  [EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
  Sent: Friday, June 13, 2008 11:11 AM
  To: [EMAIL PROTECTED]
  Subject: Iterate creating variables?

  I have twenty-five checkboxes I need to create (don't ask):

  self.checkbox1 = ...
  self.checkbox2 = ...
  .
  .
  .
  self.checkbox25 = ...

  Right now, my code has 25 lines in it, one for each checkbox, since
  these are all variables.

  Is there a way to write a loop so that I can have fewer lines of code
  but still keep the variables?

  I've tried:

  for o in xrange(25):
  self.checkbox[o] = ...

  which didn't work, and

  for o in xrange(25):
  self.checkbox[''%d'%(o)] = ...

  which also didn't work.

  Both give the error message: Attribute error: Main.App has no
  attribute checkbox, which clearly indicates that I'm not keeping
  the variability aspect I want.

  Is there a way?

  I appreciate any and all answers!

 Either store the checkboxes in an array or hash/dictionary.  If that's
 not practical, then
 You can use strings to build the code and use eval to execute the string
 as code.  Ex:

 for i in range(10):
 code = %d + %d % (i, i)
 print eval(code)

Don't do this.  You want

for idx in range(10):
setattr(self, 'checkbox_%i' % idx)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Notify of change to list

2008-06-16 Thread Mike Kent
I recently wanted to do the same kind of thing.  See this tread:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/f27c3b7950424e1c
for details on how to do it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zipping python modules

2008-06-16 Thread Larry Bates

Brian Vanderburg II wrote:
I've installed Python 2.5 on MSW and it works.  I'm preparing it to run 
from a thumb drive so I can run applications by dropping them onto the 
python.exe or from command line/etc.  It works but the size is quite 
large.  I've compressed most of the executables with UPX even the dlls 
under site-packages, but is there a way I could compress the top-level 
'lib' directory into a python.zip instead so save some space, and do I 
need the 'test' directory (which is about 10MB itself)?


Brian Vanderburg II


With thumb drives now being 2-4Gb what possible need would there be to worry 
about 10Mb?  Remember by zipping things you are trading performance for size as 
well.


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


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Paul McGuire
1. With the current dict, the following code

a = { A : 1, B : 2 }
b = { B : 2, A : 1 }

a==b evaluates to  True.  I assume that if these were odicts, this
would evaluate to False.

2. Will odict.byindex support slicing?

3. Will odict inherit from dict?

4. The current dict API (as of Python 2.5) is given by dir as:

['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__',
'__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__',
'__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
'__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy',
'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys',
'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update',
'values']

If I read your PEP correctly, you propose adding:

byindex
sort
reverse
__reverse__ (should be '__reversed__', to match list's reverse
iterator)

(This isn't really a question, your PEP was not completely explicit
about what odict's API would be, so I thought enumerating what dict
does currently might illuminate some other unresolved aspects of
odict.  For instance, since odict is somewhat list-like in its notion
of keys and values, will pop support list-like popping as well as what
dict currently provides?  Will you need a 'popbyindex' for the same
reason you need 'byindex', so that you have unambiguous lookup of
items by index vs. by key.  Perhaps doing dir(list) will help you to
see other items to resolve/clarify.)

5. The more I think and write about this, the more struck I am at the
similarity of odict and the ParseResults class in pyparsing.  For
instance, in ParseResults, there is also support for dict-style and
list-style item referencing, and I chose to restrict some cases so
that using [] notation would not be ambiguous.  You might want to add
pyparsing.ParseResults as another reference of current odicts in the
wild (although ParseResults implements quite a bit of additional
behavior that would not be required or necessarily appropriate for
odict).

I vote +0 on this PEP - I've never personally needed an odict, but I
can see how some of the XML and ORM coding would be simplified by one.

-- Paul

(I could go either way on the name 'odict' or 'ordereddict'.  Given
the desire for this to evenutally become a built-in, keep the name
short.  On the other hand, collections already has 'defaultdict', so
is 'ordereddict' so bad?)



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


Who is using python-ldap with Python 1.5.x and 2.0-2.2?

2008-06-16 Thread Michael Ströder

HI!

I'd like to hear from the Python community whether support for Python 
version prior to 2.3 is still needed in python-ldap. Please tell me 
which Python version you're using and why it'd be important for you to 
have python-ldap updates still supporting it.


BTW: Actually older Python versions are not tested with recent 
python-ldap since at least two years. But I'd like to clearly decide on 
that.


Ciao, Michael.
--
http://mail.python.org/mailman/listinfo/python-list


haif riends how do you

2008-06-16 Thread google
hi friends
COMMON DO YOU SEE THE DIFFERNT PICTURE AND INFORMATION
COMMON LETS GOO

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


Re: Who is using python-ldap with Python 1.5.x and 2.0-2.2?

2008-06-16 Thread Jeroen Ruigrok van der Werven
-On [20080616 15:55], Michael Ströder ([EMAIL PROTECTED]) wrote:
I'd like to hear from the Python community whether support for Python 
version prior to 2.3 is still needed in python-ldap. Please tell me 
which Python version you're using and why it'd be important for you to 
have python-ldap updates still supporting it.

Not that I use python-ldap at work, but our lowest Python version is 2.3 and
we're working towards making 2.5 the default.

Hopefully that helps you for versions used. :)

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
But the time has come when all good things shall pass...
--
http://mail.python.org/mailman/listinfo/python-list

Re: sorted or .sort() ?

2008-06-16 Thread Hrvoje Niksic
Peter Bengtsson [EMAIL PROTECTED] writes:

 Does that mean that .sort() is more efficient and should be favored
 when you can (i.e. when you don't mind changing the listish object)?

Yes.  Note that it's not the listish object, the sort method is
implemented on actual lists, not on any sequence.
--
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread Paul McGuire
:)

Yes, I thought about that even as I was writing that post.  But I also said,
ParseResults implements quite a bit of additional behavior that would not
be required or necessarily appropriate for  odict.  Even if odict existed,
I think I would have needed ParseResults anyway (but using an odict
internally might have simplified things for me, instead of the combined list
and dict that I have now).

-- Paul


-Original Message-
From: Shane Geiger [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 16, 2008 9:20 AM
To: Paul McGuire
Cc: python-list@python.org
Subject: Re: PEP 372 -- Adding an ordered directory to collections

Paul,

You seem to be contradicting yourself.  You may have never needed an odict,
yet you seem to have implemented one on your own.  Maybe you needed one but
did not realize it?

Shane
 5. The more I think and write about this, the more struck I am at the 
 similarity of odict and the ParseResults class in pyparsing.  For 
 instance, in ParseResults, there is also support for dict-style and 
 list-style item referencing, and I chose to restrict some cases so 
 that using [] notation would not be ambiguous.  You might want to add 
 pyparsing.ParseResults as another reference of current odicts in the 
 wild (although ParseResults implements quite a bit of additional 
 behavior that would not be required or necessarily appropriate for 
 odict).

 I vote +0 on this PEP - I've never personally needed an odict, but I 
 can see how some of the XML and ORM coding would be simplified by one.

   

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

Leading the Campaign for Economic and Financial Literacy

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


Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread George Sakkis
On Jun 16, 5:04 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 Diez B. Roggisch wrote:
  George Sakkis schrieb:
  I have a situation where one class can be customized with several
  orthogonal options. Currently this is implemented with (multiple)
  inheritance but this leads to combinatorial explosion of subclasses as
  more orthogonal features are added. Naturally, the decorator pattern
  [1] comes to mind (not to be confused with the the Python meaning of
  the term decorator).

  However, there is a twist. In the standard decorator pattern, the
  decorator accepts the object to be decorated and adds extra
  functionality or modifies the object's behavior by overriding one or
  more methods. It does not affect how the object is created, it takes
  it as is. My multiple inheritance classes though play a double role:
  not only they override one or more regular methods, but they may
  override __init__ as well. Here's a toy example:

  class Joinable(object):
      def __init__(self, words):
          self.__words = list(words)
      def join(self, delim=','):
          return delim.join(self.__words)

  class Sorted(Joinable):
      def __init__(self, words):
          super(Sorted,self).__init__(sorted(words))
      def join(self, delim=','):
          return '[Sorted] %s' % super(Sorted,self).join(delim)

  class Reversed(Joinable):
      def __init__(self, words):
          super(Reversed,self).__init__(reversed(words))
      def join(self, delim=','):
          return '[Reversed] %s' % super(Reversed,self).join(delim)

  class SortedReversed(Sorted, Reversed):
      pass

  class ReversedSorted(Reversed, Sorted):
      pass

  if __name__ == '__main__':
      words = 'this is a test'.split()
      print SortedReversed(words).join()
      print ReversedSorted(words).join()

  So I'm wondering, is the decorator pattern applicable here ? If yes,
  how ? If not, is there another way to convert inheritance to
  delegation ?

  Factory - and dynamic subclassing, as shown here:

  import random

  class A(object):
       pass

  class B(object):
       pass

  def create_instance():
       superclasses = tuple(random.sample([A, B], random.randint(1, 2)))
       class BaseCombiner(type):

           def __new__(mcs, name, bases, d):
               bases = superclasses + bases
               return type(name, bases, d)

       class Foo(object):
           __metaclass__ = BaseCombiner
       return Foo()

  for _ in xrange(10):
       f = create_instance()
       print f.__class__.__bases__

 Right now I see of course that I could have spared myself the whole
 __metaclass__-business and directly used type()... Oh well, but at least it
 worked :)

 Diez


Ok, I see how this would work (and it's trivial to make it cache the
generated classes for future use) but I guess I was looking for a more
mainstream approach, something that even a primitive statically
typed language could run :) Even in Python though, I think of Runtime
Type Generation like eval(); it's good that it exists but it should be
used as a last resort. Also RTG doesn't play well with pickling.

Since I don't have many useful subclasses so far, I'll stick with
explicit inheritance for now but I'll consider RTG if the number of
combinations becomes a real issue.

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


sexe day

2008-06-16 Thread suresh
u want the all sexye flimes ues this

   u want me see  this ***
***
   http;//lesbiangroupsexy.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


### hai, make money very simple on internet. earn at home very easily .........###

2008-06-16 Thread jeeno
Hello friends  guys,

I want to tell you about great site I found. They pay me to read e-
mail,
visit sign in the web sites and much more. earn easily without
investment.

It's free to join and easy to sign up! CLICK THIS
LINK TO VISIT: http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
http://www.ippomails.net/pages/index.php?refid=veeramani
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread Diez B. Roggisch
 Ok, I see how this would work (and it's trivial to make it cache the
 generated classes for future use) but I guess I was looking for a more
 mainstream approach, something that even a primitive statically
 typed language could run :) Even in Python though, I think of Runtime
 Type Generation like eval(); it's good that it exists but it should be
 used as a last resort. Also RTG doesn't play well with pickling.
 
 Since I don't have many useful subclasses so far, I'll stick with
 explicit inheritance for now but I'll consider RTG if the number of
 combinations becomes a real issue.

I wouldn't compare the usage of the type-constructor to eval. Python *is*
a dynamic language, and it explicitly exposes parts of it's internals
through things like metaclasses, descriptors and such.

And your requirements simply can't be met by a traditional language. There
it's either decoration or similar approaches, or nothing - especially you
can't create objects that will survive static type-analysis with aggregated
subclasses. You must lose that information through the delegation-nature of
these recipes.

Diez


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


'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Ethan Furman

Greetings.

The strip() method of strings works from both ends towards the middle.
Is there a simple, built-in way to remove several characters from a 
string no matter their location? (besides .replace() ;)


For example:
.strip -- 'www.example.com'.strip('cmowz.')
'example'
.??? -- --- 'www.example.com'.strip('cmowz.')
'exaple'
--
Ethan

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


Re: py2exe 0.6.8 released

2008-06-16 Thread Larry Bates

Jimmy Retzlaff wrote:

py2exe 0.6.8 released
=

py2exe is a Python distutils extension which converts Python scripts
into executable Windows programs, able to run without requiring a
Python installation. Console and Windows (GUI) applications, Windows
NT services, exe and dll COM servers are supported.

Changes in 0.6.8:

* Support for relative imports.

* Fix MemoryLoadLibrary to handle loading function addresses by ordinal
  numbers. Patch and test by Matthias Miller.

* Using the options compressed=1, bundle_files=3, and zipfile=None at
  the same time now works; patch from Alexey Borzenkov.

* Allow renaming of single-executable files; patch from Alexey
  Borzenkov.

* Embedding icon resources into the image now works correctly even for
  ico files containing multiple images.

* pyd files from different packages with the same filename no longer
  conflict. Patch from Grant Edwards.

* There are new samples for the 'typelibs' support, including the new
  option of pre-generating a typelib and specifying the file as an
  input to py2exe.

* The test suite is now included in the source distribution.


Changes in 0.6.6:

* Better support for Python 2.5.

* Experimental support for 64-bit builds of Python on win64.

* Better ISAPI support.

* New samples for ISAPI and COM servers.

* Support for new command-line styles when building Windows services.

Changes in 0.6.5:

* Fixed modulefinder / mf related bugs introduced in 0.6.4. This
  will be most evident when working with things like
  win32com.shell and xml.xpath.

* Files no longer keep read-only attributes when they are copied
  as this was causing problems with the copying of some MS DLLs.

Changes in 0.6.4:

* New skip-archive option which copies the Python bytecode files
  directly into the dist directory and subdirectories - no
  archive is used.

* An experimental new custom-boot-script option which allows a
  boot script to be specified (e.g., --custom-boot-script=cbs.py)
  which can do things like installing a customized stdout
  blackhole. See py2exe's boot_common.py for examples of what can
  be done. The custom boot script is executed during startup of
  the executable immediately after boot_common.py is executed.

* Thomas Heller's performance improvements for finding needed
  modules.

* Mark Hammond's fix for thread-state errors when a py2exe
  created executable tries to use a py2exe created COM DLL.

Changes in 0.6.3:

* First release assembled by py2exe's new maintainer, Jimmy
  Retzlaff. Code changes in this release are from Thomas Heller
  and Gordon Scott.

* The dll-excludes option is now available on the command line.
  It was only possible to specify that in the options argument to
  the setup function before.

  The dll-excludes option can now be used to filter out dlls like
  msvcr71.dll or even w9xpopen.exe.

* Fix from Gordon Scott: py2exe crashed copying extension modules
  in packages.

Changes in 0.6.2:

* Several important bugfixes:

  - bundled extensions in packages did not work correctly, this
made the wxPython single-file sample fail with newer wxPython
versions.

  - occasionally dlls/pyds were loaded twice, with very strange
effects.

  - the source distribution was not complete.

  - it is now possible to build a debug version of py2exe.

Changes in 0.6.1:

* py2exe can now bundle binary extensions and dlls into the
  library-archive or the executable itself.  This allows to
  finally build real single-file executables.

  The bundled dlls and pyds are loaded at runtime by some special
  code that emulates the Windows LoadLibrary function - they are
  never unpacked to the file system.

  This part of the code is distributed under the MPL 1.1, so this
  license is now pulled in by py2exe.

* By default py2exe now includes the codecs module and the
  encodings package.

* Several other fixes.

Homepage:

http://www.py2exe.org

Download from the usual location:

http://sourceforge.net/project/showfiles.php?group_id=15583

Enjoy,
Jimmy


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php



Everyone,

Thanks for all your hard work on py2exe, it is greatly appreciated.

-Larry Bates

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


Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Calvin Spealman

On Jun 16, 2008, at 12:58 PM, Ethan Furman wrote:


Greetings.

The strip() method of strings works from both ends towards the middle.
Is there a simple, built-in way to remove several characters from a  
string no matter their location? (besides .replace() ;)


For example:
.strip -- 'www.example.com'.strip('cmowz.')
'example'
.??? -- --- 'www.example.com'.strip('cmowz.')
'exaple'


 re.sub('|'.join('cmowz.'), www.example.com)
'.exaple.'


--
Ethan

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


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


Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Cédric Lucantis
Hi,

 Greetings.

 The strip() method of strings works from both ends towards the middle.
 Is there a simple, built-in way to remove several characters from a
 string no matter their location? (besides .replace() ;)

 For example:
 .strip -- 'www.example.com'.strip('cmowz.')
 'example'
 .??? -- --- 'www.example.com'.strip('cmowz.')
 'exaple'
 --

I don't see any string method to do that, but you can use a regexp :

 re.sub('[cmowz.]', '', 'www.example.com')
'exaple'

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Larry Bates

Ethan Furman wrote:

Greetings.

The strip() method of strings works from both ends towards the middle.
Is there a simple, built-in way to remove several characters from a 
string no matter their location? (besides .replace() ;)


For example:
.strip -- 'www.example.com'.strip('cmowz.')
'example'
.??? -- --- 'www.example.com'.strip('cmowz.')
'exaple'
--
Ethan


filter()

 removeChars = ';j'
 filter(lambda c: c not in removeChars, x)
'asdfklasdfkl'


or

a list comprehension

x=asdfjkl;asdfjkl;
 ''.join([c for c in x if c not in ';'])
'asdfjklasdfjkl'

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


Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Ian Kelly
On Mon, Jun 16, 2008 at 4:34 AM, Bart Kastermans [EMAIL PROTECTED] wrote:
 This is interesting.  I had never attempted to verify a big O
 statement
 before, and decided that it would be worth trying.  So I wrote some
 code to
 collect data, and I can't find that it goes quadratic.  I have the
 graph
 at

 http://kasterma.wordpress.com/2008/06/16/complexity-of-string-concatenation/

 It looks piecewise linear to me.

I don't think there's any question that it's quadratic.  Just look at
the C code, and you'll see that every time you concatenate the entire
string has to be copied.  Remember that the copy code uses memcpy from
the C library, though, so it's quite fast.  If you're not seeing it
for relatively small strings, it's probably that the major time
component is the Python looping construct, not the copy operation.

I tried it at lengths of multiples of 10, and it remained linear up
until 1E6.  At 1E7, it appears to turn quadratic.  I tried 1E8, but it
hasn't finished yet.  I expect it to take the better part of an hour.

 from timeit import Timer
 a = Timer(a += 'a', a = '')
 a.timeit(10)
6.9841280492255464e-006
 a.timeit(100)
2.7936511287407484e-005
 a.timeit(1000)
0.00043525084856810281
 a.timeit(1)
0.0049266038004134316
 a.timeit(10)
0.046758456731367914
 a.timeit(100)
0.38496261396358022
 a.timeit(1000)
20.320074199374631

Even though it doesn't become quadratic until 1E7, it's still up to an
order of magnitude faster to use str.join for smaller strings, though:

 b = Timer(''.join(['a'] * 100))
 b.timeit(1)
0.044094989726346512

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


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread ivarnelispam
I'm very happy to see this PEP. I have needed to use ordered
dictionaries many times, and this has always felt to me like a
surprising omission from Python.
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Maric Michaud
Le Monday 16 June 2008 18:58:06 Ethan Furman, vous avez écrit :
 The strip() method of strings works from both ends towards the middle.
 Is there a simple, built-in way to remove several characters from a
 string no matter their location? (besides .replace() ;)

 For example:
 .strip -- 'www.example.com'.strip('cmowz.')
 'example'
 .??? -- --- 'www.example.com'.strip('cmowz.')
 'exaple'

As Larry Bates said the python way is to use str.join, but I'd do it with a 
genexp for memory saving, and a set to get O(1) test of presence.

to_remove = set('chars')
''.join(e for in string_ if e not in to_remove)

Note that this one will hardly be defeated by other idioms in python (even 
regexp).

Using a genexp is free and a good practice, using a set, as it introduce one 
more step, can be considered as premature optimisation and the one liner :

''.join(e for in string_ if e not in 'chars')

may be preferred.

-- 
_

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


Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Jean-Paul Calderone

On Mon, 16 Jun 2008 10:41:05 -0600, Ian Kelly [EMAIL PROTECTED] wrote:

On Mon, Jun 16, 2008 at 4:34 AM, Bart Kastermans [EMAIL PROTECTED] wrote:

This is interesting.  I had never attempted to verify a big O
statement
before, and decided that it would be worth trying.  So I wrote some
code to
collect data, and I can't find that it goes quadratic.  I have the
graph
at

http://kasterma.wordpress.com/2008/06/16/complexity-of-string-concatenation/

It looks piecewise linear to me.


I don't think there's any question that it's quadratic.  Just look at
the C code, and you'll see that every time you concatenate the entire
string has to be copied.


It will depend what version of Python you're using and the *exact* details
of the code in question.  An optimization was introduced where, if the
string being concatenated to is not referred to anywhere else, it will be
re-sized in place.  This means you'll probably see sub-quadratic behavior,
but only with a version of Python where this optimization exists and only
if the code can manage to trigger it.

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


Python-URL! - weekly Python news and links (Jun 16)

2008-06-16 Thread Gabriel Genellina
QOTW:  The problem [with C++] is, I never feel like I'm programing
the *problem*, I always feel like I'm programming the *language*. - Roy Smith


Alternatives to the Decimal type:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9cd6dae725268afb/

How to invert a dictionary:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a8222b9dd036e4ef/

Why wxPython is not a standard module (and why some consider
it unpythonic):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/fde7680a07b79cb0/

Why map(None, ...) behaves in the specific way it does:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/fe79adf209747a52/

Raw strings, backslashes, filenames, GUI input... A big confusion
finally resolved:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/43940eb4de069f63/

A simple and suposedly safe eval() that isn't safe at
all - malicious users can execute arbitrary code:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/40d765b5eedfb57/

How networks work - mostly off topic, but clearly and simply explained:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e84dff684899c3f2/

Confusing the Google Data API, the services it access, and their licenses:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b632eee9dc98b26c/




Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiats:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi
http://python.de/backend.php
For more, see
http://www.syndic8.com/feedlist.php?ShowMatch=pythonShowStatus=all
The old 

Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Peter Otten
Ethan Furman wrote:

 The strip() method of strings works from both ends towards the middle.
 Is there a simple, built-in way to remove several characters from a
 string no matter their location? (besides .replace() ;)

 identity = .join(map(chr, range(256)))
 'www.example.com'.translate(identity, 'cmowz.')
'exaple'

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


Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Raymond Hettinger
On Jun 16, 10:09 am, Peter Otten [EMAIL PROTECTED] wrote:
 Ethan Furman wrote:
  The strip() method of strings works from both ends towards the middle.
  Is there a simple, built-in way to remove several characters from a
  string no matter their location? (besides .replace() ;)
  identity = .join(map(chr, range(256)))
  'www.example.com'.translate(identity, 'cmowz.')

 'exaple'

And in Py2.6, you'll be able to simplify further:

 'abcde'.translate(None, 'bd')
'ace'


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


Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Ian Kelly
On Mon, Jun 16, 2008 at 11:09 AM, Jean-Paul Calderone
[EMAIL PROTECTED] wrote:
 It will depend what version of Python you're using and the *exact* details
 of the code in question.  An optimization was introduced where, if the
 string being concatenated to is not referred to anywhere else, it will be
 re-sized in place.  This means you'll probably see sub-quadratic behavior,
 but only with a version of Python where this optimization exists and only
 if the code can manage to trigger it.

AFAICT, PyString_Concat never calls _PyString_Resize.  Am I looking in
the wrong place?

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


Re: sorted or .sort() ?

2008-06-16 Thread Raymond Hettinger
On Jun 16, 5:11 am, Peter Bengtsson [EMAIL PROTECTED] wrote:
 My poor understanding is that the difference between `sorted(somelist,
 key=lambda x:...)` and `somelist.sort(lambda x,y...)` is that one
 returns a new list and the other sorts in-place.

 Does that mean that .sort() is more efficient and should be favored
 when you can (i.e. when you don't mind changing the listish object)?

Here's how sorted() works:

def sorted(iterable, *args, **kwds):
s = list(iterable)
s.sort(*args, **kwds)
return s

So, sorted() runs at the same speed as list.sort() except for the step
where the input gets copied.  For list inputs, that extra time is
trivial compared to the cost of actually doing the sort.  I wouldn't
worry about the negligible performance difference.  Use whichever fits
best in your program.

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


Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread Gerard flanagan

George Sakkis wrote:

I have a situation where one class can be customized with several
orthogonal options. Currently this is implemented with (multiple)
inheritance but this leads to combinatorial explosion of subclasses as
more orthogonal features are added. Naturally, the decorator pattern
[1] comes to mind (not to be confused with the the Python meaning of
the term decorator).

However, there is a twist. In the standard decorator pattern, the
decorator accepts the object to be decorated and adds extra
functionality or modifies the object's behavior by overriding one or
more methods. It does not affect how the object is created, it takes
it as is. My multiple inheritance classes though play a double role:
not only they override one or more regular methods, but they may
override __init__ as well. Here's a toy example:



I don't know if it will map to your actual problem, but here's a 
variation of your toy code. I was thinking the Strategy pattern, 
different classes have different initialisation strategies? But then you 
could end up with as many Strategy classes as subclasses, I don't know.
(Also in vaguely similar territory - 
http://bazaar.launchpad.net/~grflanagan/python-rattlebag/trunk/annotate/head:/src/template.py

)


class MetaBase(type):

def __init__(cls, name, bases, data):
cls.strategies = []
cls.prefixes = []
for base in bases:
print base
if hasattr(base, 'strategy'):
cls.strategies.append(base.strategy)
if hasattr(base, 'prefix'):
cls.prefixes.append(base.prefix)
super(MetaBase, cls).__init__(name, bases, data)

class Joinable(object):
__metaclass__ = MetaBase
strategy = list
prefix = ''

def __init__(self, words):
self._words = words
for strategy in self.strategies:
self._words = strategy(self._words)

def join(self, delim=','):
return '%s %s' % (' '.join(self.prefixes), delim.join(self._words))

class Sorted(Joinable):
strategy = sorted
prefix = '[sorted]'

class Reversed(Joinable):
strategy = reversed
prefix = '[reversed]'

class SortedReversed(Sorted, Reversed):
pass

class ReversedSorted(Reversed, Sorted):
pass

if __name__ == '__main__':
words = 'this is a test'.split()
print SortedReversed(words).join()
print ReversedSorted(words).join()

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


Re: bpython - fancy Python shell

2008-06-16 Thread Sebastian lunar Wiesner
Wolfgang Grafen [EMAIL PROTECTED]:

 I couldn't get it work on Solaris (modified some lines for Python2.3).
If solaris doesn't have a readline library, you might try to compile gnu
readline, and recompile python (also a chance to get the current version
2.5) 

 One reason was that I had to download pyreadline separately
 - I did than but now pyreadline requires either ironpython or
a windows installation. 

pyreadline is a windows-only thing.  Since readline is a standard module on
most unix systems and linux, there was no need to implement pyreadline for
these systems.  It would have been difficult anyway, since the windows
console is completely different to unix consoles (which are fairly
compatible to each other, a outcome of POSIX efforts).

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


sqlite3 and Python 2.5.1

2008-06-16 Thread milan_sanremo
I have sqlite installed, but when I try to import sqlite3 I receive:

Python 2.5.1 (r251:54863, Nov  3 2007, 02:54:36) [C] on sunos5
Type help, copyright, credits or license for more information.
 import sqlite3
Traceback (most recent call last):
  File stdin, line 1, in module
ImportError: No module named sqlite3


Yet:

# find /usr/local/python -name sqlite* -print
/usr/local/python/lib/python2.5/sqlite3

# /opt/csw/bin/sqlite3
SQLite version 3.2.2
Enter .help for instructions
sqlite

What is missing?


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


Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Alex Elder
I found this article useful when dealing with strings in Python:

http://www.skymind.com/~ocrow/python_string/

It may help squeeze some more time out of your code. 8-)

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


Re: numpy: handling float('NaN') different in XP vs. Linux

2008-06-16 Thread John [H2O]



Dan Bishop wrote:
 
 
 
 Python just uses the atof() function from the underlying C library.
 Some of them handle NaN's, and some of them don't.
 
 

As a work around, how would I write this in list comprehension form:

 newlist=[]
 for i in range(len(v[1])):
try:
   newlist.append(float(v[1][i]))
except:
   newlist.append(-999.99) # or just nan possibly?




-- 
View this message in context: 
http://www.nabble.com/numpy%3A-handling-float%28%27NaN%27%29-different-in-XP-vs.-Linux-tp17835502p17870333.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: sqlite3 and Python 2.5.1

2008-06-16 Thread Lie
On Jun 17, 12:59 am, milan_sanremo [EMAIL PROTECTED] wrote:
 I have sqlite installed, but when I try to import sqlite3 I receive:

 Python 2.5.1 (r251:54863, Nov  3 2007, 02:54:36) [C] on sunos5
 Type help, copyright, credits or license for more information.
 import sqlite3

 Traceback (most recent call last):
   File stdin, line 1, in module
 ImportError: No module named sqlite3



 Yet:

 # find /usr/local/python -name sqlite* -print
 /usr/local/python/lib/python2.5/sqlite3

 # /opt/csw/bin/sqlite3
 SQLite version 3.2.2
 Enter .help for instructions
 sqlite

 What is missing?

Did you, by chance, happened to compile your Python yourself? From
what I see here:
http://www.megasolutions.net/python/python-unix-install,-sqlite3-78710.aspx
Python's source doesn't include the sqlite3 source, it only contains
pysqlite interface, so when compiling python you need to get sqlite3
too.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread George Sakkis
On Jun 16, 1:49 pm, Gerard flanagan [EMAIL PROTECTED] wrote:

 George Sakkis wrote:
  I have a situation where one class can be customized with several
  orthogonal options. Currently this is implemented with (multiple)
  inheritance but this leads to combinatorial explosion of subclasses as
  more orthogonal features are added. Naturally, the decorator pattern
  [1] comes to mind (not to be confused with the the Python meaning of
  the term decorator).

  However, there is a twist. In the standard decorator pattern, the
  decorator accepts the object to be decorated and adds extra
  functionality or modifies the object's behavior by overriding one or
  more methods. It does not affect how the object is created, it takes
  it as is. My multiple inheritance classes though play a double role:
  not only they override one or more regular methods, but they may
  override __init__ as well. Here's a toy example:

 I don't know if it will map to your actual problem, but here's a
 variation of your toy code. I was thinking the Strategy pattern,
 different classes have different initialisation strategies? But then you
 could end up with as many Strategy classes as subclasses, I don't know.
 (Also in vaguely similar territory 
 -http://bazaar.launchpad.net/~grflanagan/python-rattlebag/trunk/annota...
 )

 class MetaBase(type):

      def __init__(cls, name, bases, data):
          cls.strategies = []
          cls.prefixes = []
          for base in bases:
              print base
              if hasattr(base, 'strategy'):
                  cls.strategies.append(base.strategy)
              if hasattr(base, 'prefix'):
                  cls.prefixes.append(base.prefix)
          super(MetaBase, cls).__init__(name, bases, data)

 class Joinable(object):
      __metaclass__ = MetaBase
      strategy = list
      prefix = ''

      def __init__(self, words):
          self._words = words
          for strategy in self.strategies:
              self._words = strategy(self._words)

      def join(self, delim=','):
          return '%s %s' % (' '.join(self.prefixes), delim.join(self._words))

 class Sorted(Joinable):
      strategy = sorted
      prefix = '[sorted]'

 class Reversed(Joinable):
      strategy = reversed
      prefix = '[reversed]'

 class SortedReversed(Sorted, Reversed):
      pass

 class ReversedSorted(Reversed, Sorted):
      pass

 if __name__ == '__main__':
      words = 'this is a test'.split()
      print SortedReversed(words).join()
      print ReversedSorted(words).join()

This doesn't solve the original problem, the combinatorial explosion
of empty subclasses. At the end of the day, I'd like a solution that
uses a (mostly) flat, single-inheritance, hierarchy, allowing the
client say:

j = Joinable(words)
if sort:
  j = Sorted(j)
if reverse:
  j = Reversed(j)
...
print j.join()


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


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-16 Thread [EMAIL PROTECTED]
On 16 juin, 10:37, Armin Ronacher [EMAIL PROTECTED] wrote:
 Abstract
 

 This PEP proposes an ordered dictionary as a new data structure for
 the ``collections`` module, called odict in this PEP for short.  The
 proposed API incorporates the experiences gained from working with
 similar implementations that exist in various real-world applications
 and other programming languages.

(snip)

+1

insertion-ordered dicts are something I often need, and while there
are usable workarounds, they either require boilerplate code,
introduce external dependancies to (possibly unoptimised) code or make
you reinvent the (square) wheel, all of which is (IMHO) below average
Python's standard regarding data structures.

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


Re: Configuration files

2008-06-16 Thread Robert
Does ConfigParser allow writing configuration changes also?


Dennis Lee Bieber [EMAIL PROTECTED] schreef in bericht
news:[EMAIL PROTECTED]
 On Sat, 14 Jun 2008 21:27:19 +0200, Robert [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:

  What is the most Pythonic way to maintain a configuration file?
  Are there any libraries mimicking registry / ini file writing that many
  windows programming languages/environments offer?
 
 Uhm... Section 5.17 (at least, in v2.4.x) Library Reference:
 ConfigParser
 -- 
 Wulfraed Dennis Lee Bieber KD6MOG
 [EMAIL PROTECTED] [EMAIL PROTECTED]
 HTTP://wlfraed.home.netcom.com/
 (Bestiaria Support Staff: [EMAIL PROTECTED])
 HTTP://www.bestiaria.com/


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


Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Jean-Paul Calderone

On Mon, 16 Jun 2008 11:30:19 -0600, Ian Kelly [EMAIL PROTECTED] wrote:

On Mon, Jun 16, 2008 at 11:09 AM, Jean-Paul Calderone
[EMAIL PROTECTED] wrote:

It will depend what version of Python you're using and the *exact* details
of the code in question.  An optimization was introduced where, if the
string being concatenated to is not referred to anywhere else, it will be
re-sized in place.  This means you'll probably see sub-quadratic behavior,
but only with a version of Python where this optimization exists and only
if the code can manage to trigger it.


AFAICT, PyString_Concat never calls _PyString_Resize.  Am I looking in
the wrong place?


Yep.  The optimization is done directly from the eval loop.  Take a look at
ceval.c, if you search for _PyString_Resize you should see it.

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


President Bush Meets Pope Before Heading to Paris

2008-06-16 Thread vaticans.org
U.S. President George Bush has met with Pope Benedict at the Vatican,
as he continues his week-long European trip.

After his talks with the pontiff, Mr. Bush was traveling to Paris,
France, where he is to give a speech later Friday on the strong
relationship between the U.S. and Europe.

U.S. National Security Advisor Stephen Hadley said Mr. Bush will urge
European leaders to work even more closely with the U.S. to help bring
peace to the Middle East.

Mr. Hadley said the trans-Atlantic relationship has been strengthened
by the current leaders in Italy, Britain, Germany, and France.

The White House says Mr. Bush's speech will also commemorate the 60th
anniversary of the Marshall Plan - the U.S. aid program that helped
rebuild Europe after the devastation caused by World War II.

The president and Mrs. Bush are then scheduled to have dinner with the
French president and Mrs. Sarkozy at the Elysee Palace. Mr. Bush and
Mr. Sarkozy hold formal talks on Saturday.

On Thursday President Bush met with Italian Prime Minister Silvio
Berlusconi and the two leaders agreed to to work together on trying to
convince Iran to give up its uranium enrichment program. Mr.
Berlusconi said Italy has a trading relation with Iran and knows that
country from the inside.

President Bush said he will consider Italy's request to join the five
permanent U.N. Security Council members and Germany in working on the
Iran nuclear issue.

But Mr. Hadley said it is always a problem when a country's commercial
ties clashes with its national security requirements.

Mr. Bush's European trip will also take him to Britain and Northern
Ireland. Earlier, he stopped in Germany and attended the annual U.S.-
European Union summit in Slovenia.


http://www.vaticans.org/index.php?/archives/1175-Pope-Benedict-XVI-hosted-US-President-George-W.-Bush-at-the-Vatican.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe 0.6.8 released

2008-06-16 Thread Robert
Being new on on Python (but otherwise experienced programmer this message 
triggered me to do the install.
It looks like a nice way to do a comprehensive check of your system.

When running one of the py2exe samples, located in 
C:\Python25\Lib\site-packages\py2exe\samples\singlefile\gui I got the 
following error when running the resulting executable:

C:\Python25\Lib\site-packages\py2exe\samples\singlefile\gui\dist\test_wx.exe\zipextimporter.py:82:
 
DeprecationWarning: The wxPython compatibility package is no longer 
automatically generated or actively maintained.  Please switch to the wx 
package as soon as possible.
Traceback (most recent call last):
  File test_wx.py, line 1, in module
  File zipextimporter.pyo, line 82, in load_module
  File wxPython\__init__.pyo, line 15, in module
  File zipextimporter.pyo, line 82, in load_module
  File wxPython\_wx.pyo, line 8, in module
  File zipextimporter.pyo, line 82, in load_module
  File wxPython\_misc.pyo, line 456, in module
AttributeError: 'module' object has no attribute 
'DateTime_GetNumberOfDaysinYear'

I know of course the real error must be on the wx part of it all.

I only have:
- a python 2.5.2 install(msi)
- a wxPython2.8-win32-unicode-2.8.7.1-py25.exe install
- a py2exe-0.6.8.win32-py2.5.exeinstall.

I have deleted C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wxPython 
because there indications that this is not needed, but other problems 
emerged.

Any clues how to proceed next?

Robert


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


Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Ian Kelly
On Mon, Jun 16, 2008 at 12:07 PM, Alex Elder [EMAIL PROTECTED] wrote:
 I found this article useful when dealing with strings in Python:

http://www.skymind.com/~ocrow/python_string/

 It may help squeeze some more time out of your code. 8-)

Things seem to have changed since then.  I'm finding that method 4 is
about 15% faster than method 5.  Whether the change is due to using a
different Python version, processor, or operating system, I couldn't
say.

I used Python 2.5.2 on an Intel Core 2 at 2 GHz running Windows XP, SP2.

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


How to request data from a lazily-created tree structure ?

2008-06-16 Thread méchoui
Problem:

- You have tree structure (XML-like) that you don't want to create
100% in memory, because it just takes too long (for instance, you need
a http request to request the information from a slow distant site).
- But you want to be able to request data from it, such has give me
all nodes that are under a //foo/bar tree, and have a child with an
baz attribute of value zzz.

Question :

Do you have any other idea to request data from a lazily-created tree
structure ?

And does it make sense to create a DOM-like structure and to use a
generic XPath engine to request the tree ? (and does this generic
XPath engine exist ?)

The idea is to have the tree structure created on the fly (we are in
python), only when the XPath engine requests the data. Hopefully the
XPath engine will not request all the data from the tree (if the
request is smart enough and does not contain **, for instance).

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


vmware job vacancy!

2008-06-16 Thread Mr Shore
A veteran engineer from VMWare Inc., Jeffrey, is being featured on
jobirn.com on Monday Jun 16, from 9am to 5pm (PST.)
He will chat with applicants who are interested in job openings in
VMWare.
He will identify qualified candidates and directly submit qualified
candidates' resumes to hiring managers.

Logon to http://jobirn.com and chat with Jeff.

Jobirn.com is a job-referral company.  It connects job applicants with
insider employees in companies.  Jobirn.com believes it gives
qualified candidates higher opportunities to catch the attention of
the right managers.  Referrers, once featured, will usually
make significant amount of bonus (Employee Referral Bonus) from his
own company,if the recommended candidates are hired.
--
http://mail.python.org/mailman/listinfo/python-list


Good cross-host IPC?

2008-06-16 Thread Kirk Strauser
We've been using NetWorkSpaces
(http://www.ddj.com/web-development/21971) for IPC on programs running
on several different machines.  Since it uses a central, shared server for
storing values, you don't have to write socket code in your various programs
to pass data back and forth.

For example, a program can request some work to be done by a random machine
on the network like so:

 from nws.client import NetWorkSpace
 space = NetWorkSpace('test')
 space.store('value', 42)
 ws.fetch('results')
43

...and a worker process can listen for work to do and return the results by
doing:

 from nws.client import NetWorkSpace
 space = NetWorkSpace('test')
 value = space.fetch('value')
 space.store('results', value + 1)

Since space.fetch() is a blocking call and the NetWorkSpaces server answers
requests in the order that they're received, this is a nice way to
coordinate a cluster.

This is pretty spiffy and works great in practice, but it feels like we're
the only people using it.  Parallel Python lives in kind of the same problem
space, but not all of our code is easily bent to its will.  Is there
another, more common way of doing this stuff?

Popularity isn't the most important thing in the world, but I like the warm
fuzzies of knowing that thousands of others are testing and using the same
project as we are.
-- 
Kirk Strauser
The Day Companies
--
http://mail.python.org/mailman/listinfo/python-list


Re: numpy: handling float('NaN') different in XP vs. Linux

2008-06-16 Thread Robert Kern

John [H2O] wrote:

Dan Bishop wrote:


Python just uses the atof() function from the underlying C library.
Some of them handle NaN's, and some of them don't.


As a work around, how would I write this in list comprehension form:

 newlist=[]
 for i in range(len(v[1])):
try:
   newlist.append(float(v[1][i]))
except:
   newlist.append(-999.99) # or just nan possibly?


from numpy import nan

def nanfloat(x):
if x.lower() == 'nan':
return nan
else:
return float(x)

newlist = [myfloat(x) for x in v[1]]

--
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: newbie question: for loop within for loop confusion

2008-06-16 Thread MRAB
On Jun 16, 7:17 am, Paul Hankin [EMAIL PROTECTED] wrote:
 On Jun 16, 2:35 pm, takayuki [EMAIL PROTECTED] wrote:



  def hasnolet2(avoid):
  fin = open('animals.txt')
  for line in fin:
  word = line.strip()

  length = len(avoid)
  x = 0
  noprint = 0

  while length -1 = x:
  if avoid[x] in word:
  noprint = noprint + 1
  x = x + 1

  if noprint == 0:
  print word

 There seems to be an indendation problem (presumably the code from
 length = len(avoid) onwards should be inside the loop). But apart from
 that, we can try to make this more 'pythonic'.

 First, python has a 'for' statement that's usually better than using
 while. We use the 'range' function that produces the numbers 0, 1, ...
 length - 1, and x takes the value of these in turn.

 Here's the last bit of your code rewritten like this:

 noprint = 0

 for x in range(length):
 if avoid[x] in word:
 noprint += 1

 if noprint == 0:
 print word

 But better, rather than using 'x' as an index, we can loop over
 letters in avoid directly. I've changed 'noprint' to be a boolean
 'should_print' too here.

 should_print = True
 for letter in avoid:
 if letter in word:
 should_print = False

 if should_print:
 print word

 We can eliminate 'should_print' completely, by using 'break' and
 'else'. A break statement in a loop causes the loop to end. If the
 loop doesn't break, the 'else' code is run when the loop's over.

 for letter in avoid:
 if letter in word:
 break
 else:
 print word

 This is almost the same as your original code, but the 'else' is
 attached to the 'for' rather that the 'if'!

 Finally, in Python 2.5 you can write this:

 if not any(letter in word for letter in avoid):
 print word

 I think this is the best solution, as it's readable and short.

Alternatively, you could use sets:

if not(set(word)  set(avoid)):
print word

(parentheses added for clarity.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple and safe evaluator

2008-06-16 Thread bvdp


Okay guys. I have the _ast based safe eval installed and working in my 
program. It appears to be working just fine. Thanks for the help.


Now, a few more questions:

1. I see that _ast is a 2.5 module?? So, for folks using my code with 
2.5 I could do something like this:


# I've got some imports here to look after the error() and warning() 
funcs 


emsg_done = 0
etx = 

def unsafe_eval(s):
 safe eval for  python 2.5 (lacks _ast) 
global emsg_done
if not emsg_done:
warning(You are using an unsafe eval() function. Please 
upgrade to Python version 2.5 or greater.)

emsg_done=1
   # need error trap here as well ...
return eval(s, {__builtins__:None}, {} )

def safe_eval(text):
similar to eval, but only works on numerical values.
global etx
try:
ast = compile(text, string, 'eval', _ast.PyCF_ONLY_AST)
except:
error(Expression error in '%s' % text)
etx = text   # for error reporting, bvdp
return _traverse(ast.body)


try:
import _ast
num_eval = safe_eval
except:
num_eval = unsafe_eval

# rest of matt's ast code follows.

Which appears to do the following: if there isn't an _ast module we just 
define an alternate, not-so-safe, function and warn the user; otherwise 
we use the safe version. I'm a bit uncomfortable with the import _ast 
being after the function which uses the code, but it seems to work.


2. I thought I'd be happy with * / + -, etc. Of course now I want to add 
a few more funcs like int() and sin(). How would I do that?


Thanks. This is looking very nice indeed.

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


Re: 32 bit or 64 bit?

2008-06-16 Thread [EMAIL PROTECTED]
On Jun 16, 12:57 am, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 On Jun 15, 11:30 pm, Christian Heimes [EMAIL PROTECTED] wrote:



  [EMAIL PROTECTED] wrote:
   I have a physical system set up in which a body is supposed to
   accelerate and to get very close to lightspeed, while never really
   attaining it. After approx. 680 seconds, Python gets stuck and tells
   me the object has passed lightspeed. I put the same equations in
   Mathematica, again I get the same mistake around 680 seconds. So I
   think, I have a problem with my model! Then I pump up the
   WorkingPrecision in Mathematica to about 10. I run the same equations
   again, and it works! At least for the first 10,000 seconds, the object
   does not pass lightspeed.
   I concluded that I need Python to work at a higher precision.

  I conclude that your algorithm is numerical wrong. It probably suffers
  from a rounding error which increases itself in every iteration.
  Increasing the precision doesn't solve your problem. It's only going to
  hide the fact that your algorithm doesn't do its job.

  Please don't get me wrong. I don't want to imply that you are an idiot
  who doesn't know what he is doing. :] Most likely you weren't taught how
  to write numerical sound algorithms. Let's all blame your school or
  university. *g*

  Numerics is a complex area and it took me more than a year to learn the
  basics. Don't be embarrassed!

 I'll try to read some. But I used mpmath to pump up the precision in
 my code, and now the problem doesn't happen. So I think it's okay for
 now.

Thanks to all contributors for your advice.

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


Re: sqlite3 and Python 2.5.1

2008-06-16 Thread Gerhard Häring
milan_sanremo wrote:
 I have sqlite installed, but when I try to import sqlite3 I receive:
 
 Python 2.5.1 (r251:54863, Nov  3 2007, 02:54:36) [C] on sunos5
 Type help, copyright, credits or license for more information.
 import sqlite3
 Traceback (most recent call last):
   File stdin, line 1, in module
 ImportError: No module named sqlite3
 
 Yet:
 
 # find /usr/local/python -name sqlite* -print
 /usr/local/python/lib/python2.5/sqlite3
 
 # /opt/csw/bin/sqlite3
 SQLite version 3.2.2
 Enter .help for instructions
 sqlite
 
 What is missing?

You compiled Python yourself. During that, the SQLite3 header files
could not be found, so the sqlite3 module was not compiled/installed.

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


Re: How to request data from a lazily-created tree structure ?

2008-06-16 Thread Diez B. Roggisch

méchoui schrieb:

Problem:

- You have tree structure (XML-like) that you don't want to create
100% in memory, because it just takes too long (for instance, you need
a http request to request the information from a slow distant site).
- But you want to be able to request data from it, such has give me
all nodes that are under a //foo/bar tree, and have a child with an
baz attribute of value zzz.

Question :

Do you have any other idea to request data from a lazily-created tree
structure ?

And does it make sense to create a DOM-like structure and to use a
generic XPath engine to request the tree ? (and does this generic
XPath engine exist ?)

The idea is to have the tree structure created on the fly (we are in
python), only when the XPath engine requests the data. Hopefully the
XPath engine will not request all the data from the tree (if the
request is smart enough and does not contain **, for instance).


Generic XPath works only with a DOM(like) structure. How else would you 
e.g. evaluate an expression like foo[last()]?



So if you really need lazy evaluation, you will need to specifically 
analyze the query of interest and see if it can be coded in a way that 
allows to forget as much of the tree as possible, or even better not 
query it.


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


Re: Simple and safe evaluator

2008-06-16 Thread George Sakkis
On Jun 16, 4:47 pm, bvdp [EMAIL PROTECTED] wrote:

 2. I thought I'd be happy with * / + -, etc. Of course now I want to add
 a few more funcs like int() and sin(). How would I do that?

For the builtin eval, just populate the globals dict with the names
you want to make available:

import math

globs = {'__builtins__' : None}

# expose selected builtins
for name in 'True False int float round abs divmod'.split():
globs[name] = eval(name)

# expose selected math constants and functions
for name in 'e pi sqrt exp log ceil floor sin cos tan'.split():
globs[name] = getattr(math,name)

return eval(s, globs, {})


The change to the _ast version is left as an exercise to the reader ;)

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


Re: sorted or .sort() ?

2008-06-16 Thread Nick Craig-Wood
Ben Finney [EMAIL PROTECTED] wrote:
  Peter Bengtsson [EMAIL PROTECTED] writes:
 
  My poor understanding is that the difference between `sorted(somelist,
  key=lambda x:...)` and `somelist.sort(lambda x,y...)` is that one
  returns a new list and the other sorts in-place.
 
  Yes.
 
  Does that mean that .sort() is more efficient and should be favored
  when you can (i.e. when you don't mind changing the listish object)?
 
  No, it means you should choose the version that expresses what you
  actually want to do.
 
  Efficiency of the programmers ??? including the unknown number of
  programmers who will have to read the code after you write it ??? is in
  many cases a much more important criterion than efficiency of the CPU.
  People's time continues to be much more expensive than computer time,
  after all.

Good advice with one caveat: sorted() was only introduced in python
2.4 so if your code must run on earlier versions then use list.sort()

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question: for loop within for loop confusion

2008-06-16 Thread Thomas Hill
On Jun 15, 6:23 pm, takayuki [EMAIL PROTECTED] wrote:
 def hasnolet(avoid):
 fin = open('animals.txt')
 for line in fin:
 word = line.strip()
 for letter in avoid:
 if letter in word:
 break
 else:
 print word

You're using the split command correctly, but you're not filtering
correctly. Consider this:

---begin---
fin = open('animals.txt')
\n.join([%s % line for line in fin if len(line.strip('abcd')) ==
len(line)])
end

Let's go slow.

\n.join([...])

1. Take everything that is in the following list, and print each one
with a carriage return appended to it.

\n.join([%s % line for line in fin ...])

2. For each line in fin, create a string that only consists of what
currently in the line variable, using string substitution.

\n.join([%s % line for line in fin if len(line.strip('abcd')) ==
len(line)])

3. Only do #2 if the length of the line after stripping out the
unnecessary characters is the same length as the line originally. This
way we filter out the lines we don't want. If we wanted the lines that
have been filtered, we can change == to != or =.

Now, I read Dive Into Python first, which through these early on in
the book. If your eyes cross looking at this, write it down and read
it again after you get a little farther into the book you're reading
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question: for loop within for loop confusion

2008-06-16 Thread Thomas Hill
On Jun 16, 2:34 pm, Thomas Hill [EMAIL PROTECTED] wrote:
 On Jun 15, 6:23 pm, takayuki [EMAIL PROTECTED] wrote:

  def hasnolet(avoid):
  fin = open('animals.txt')
  for line in fin:
  word = line.strip()
  for letter in avoid:
  if letter in word:
  break
  else:
  print word

 You're using the split command correctly, but you're not filtering
 correctly. Consider this:

 ---begin---
 fin = open('animals.txt')
 \n.join([%s % line for line in fin if len(line.strip('abcd')) ==
 len(line)])
 end

 Let's go slow.

 \n.join([...])

 1. Take everything that is in the following list, and print each one
 with a carriage return appended to it.

 \n.join([%s % line for line in fin ...])

 2. For each line in fin, create a string that only consists of what
 currently in the line variable, using string substitution.

 \n.join([%s % line for line in fin if len(line.strip('abcd')) ==
 len(line)])

 3. Only do #2 if the length of the line after stripping out the
 unnecessary characters is the same length as the line originally. This
 way we filter out the lines we don't want. If we wanted the lines that
 have been filtered, we can change == to != or =.

 Now, I read Dive Into Python first, which through these early on in
 the book. If your eyes cross looking at this, write it down and read
 it again after you get a little farther into the book you're reading

Guh, no, I'm reading the description of strip wrong. Fooey. Anyone
else able to one line it?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to request data from a lazily-created tree structure ?

2008-06-16 Thread méchoui
On Jun 16, 11:16 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 méchoui schrieb:



  Problem:

  - You have tree structure (XML-like) that you don't want to create
  100% in memory, because it just takes too long (for instance, you need
  a http request to request the information from a slow distant site).
  - But you want to be able to request data from it, such has give me
  all nodes that are under a //foo/bar tree, and have a child with an
  baz attribute of value zzz.

  Question :

  Do you have any other idea to request data from a lazily-created tree
  structure ?

  And does it make sense to create a DOM-like structure and to use a
  generic XPath engine to request the tree ? (and does this generic
  XPath engine exist ?)

  The idea is to have the tree structure created on the fly (we are in
  python), only when the XPath engine requests the data. Hopefully the
  XPath engine will not request all the data from the tree (if the
  request is smart enough and does not contain **, for instance).

 Generic XPath works only with a DOM(like) structure. How else would you
 e.g. evaluate an expression like foo[last()]?

 So if you really need lazy evaluation, you will need to specifically
 analyze the query of interest and see if it can be coded in a way that
 allows to forget as much of the tree as possible, or even better not
 query it.

 Diez

Yes, I need to make sure my requests are properly written so that the
generic XPath engine does not need all the structure in memory.

There are quite a few cases where you really don't need to load
everything at all. /a/b/*/c/d is an example. But even with an example
like /x/z[last()]/t, you don't need to load everything under the
every /x/z nodes. You just need to check for the latest one, and make
sure there is a t node under it.

Anyway, if I need to make requests that need all the data... that
means that the need for lazy instantiation of nodes disappears,
right ?
--
http://mail.python.org/mailman/listinfo/python-list


Please explain Python __whatever__ construct.

2008-06-16 Thread bsagert
After a couple of weeks studying Python, I already have a few useful
scripts, including one that downloads 1500 Yahoo stock quotes in 6
seconds. However, many things are puzzling to me. I keep on seeing
things like __main__ in scripts.  A more obscure example would be
__add__ used in string concatenation. For example, I can use Hello
+world (or just Hello world) to join those two words. But I can
also use Hello .__add__(world). When and why would I ever use
__main__ or the many other __whatever__ constructs?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple and safe evaluator

2008-06-16 Thread bvdp

George Sakkis wrote:

On Jun 16, 4:47 pm, bvdp [EMAIL PROTECTED] wrote:


2. I thought I'd be happy with * / + -, etc. Of course now I want to add
a few more funcs like int() and sin(). How would I do that?


For the builtin eval, just populate the globals dict with the names
you want to make available:

import math

globs = {'__builtins__' : None}

# expose selected builtins
for name in 'True False int float round abs divmod'.split():
globs[name] = eval(name)

# expose selected math constants and functions
for name in 'e pi sqrt exp log ceil floor sin cos tan'.split():
globs[name] = getattr(math,name)

return eval(s, globs, {})



Thanks. That was easy :)


The change to the _ast version is left as an exercise to the reader ;)


And I have absolutely no idea on how to do this. I can't even find the 
_ast import file on my system. I'm assuming that the _ast definitions 
are buried in the C part of python, but that is just a silly guess.


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


  1   2   >