Re: No trees in the stdlib?

2009-06-26 Thread João Valverde

João Valverde wrote:

Aahz wrote:

In article ,
Tom Reed   wrote:
 
Why no trees in the standard library, if not as a built in? I 
searched the archive but couldn't find a relevant discussion. Seems 
like a glaring omission considering the batteries included 
philosophy, particularly balanced binary search trees. No interest, 
no good implementations, something other reason? Seems like a good 
fit for the collections module. Can anyone shed some light?



What do you want such a tree for?  Why are dicts and the bisect module
inadequate?  Note that there are plenty of different tree 
implementations

available from either PyPI or the Cookbook.
  
A hash table is very different to a BST.  They are both useful. The 
bisect module I'm not familiar with, I'll have to look into that, thanks.


I have found pyavl on the web, it does the job ok, but there no 
implementations for python3 that I know of.


Simple example usage case: Insert string into data structure in sorted 
order if it doesn't exist, else retrieve it.


After browsing the bisect module I don't think it is the complete 
answer. Please correct me if I'm mistaken but...


Ignoring for a moment that subjectively I feel this is not very pythonic 
for my use case, if I get back the insertion position, doesn't that mean 
I have to go over on average N/2 items on a linked list to insert the 
item in position? Maybe less for sophisticated implementations but still 
O(n)? That doesn't compare favorably to the cost of (possibly) having to 
rebalance a tree on insertion.

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


Re: No trees in the stdlib?

2009-06-26 Thread Jason Scheirer
On Jun 25, 10:32 pm, [email protected] (Aahz) wrote:
> In article ,
> Tom Reed   wrote:
>
>
>
> >Why no trees in the standard library, if not as a built in? I searched
> >the archive but couldn't find a relevant discussion. Seems like a
> >glaring omission considering the batteries included philosophy,
> >particularly balanced binary search trees. No interest, no good
> >implementations, something other reason? Seems like a good fit for the
> >collections module. Can anyone shed some light?
>
> What do you want such a tree for?  Why are dicts and the bisect module
> inadequate?  Note that there are plenty of different tree implementations
> available from either PyPI or the Cookbook.
> --
> Aahz ([email protected])           <*>        http://www.pythoncraft.com/
>
> "as long as we like the same operating system, things are cool." --piranha

...And heapq is more-or-less an emulation of a tree structure in its
underlying model. I once wrote a binary sorted tree data structure for
Python in C. It performed anywhere from 15-40% worse than dicts. I
think with optimization it will only perform 10% worse than dicts at
best.

Oh hey maybe that is why trees aren't an emphasized part of the
standard. They are going to be much slower than the ultra-optimized
dicts already in the standard lib.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Ulrich Eckhardt
Robert Kern wrote:
> I wish people would stop representing decimal floating point arithmetic as
> "more accurate" than binary floating point arithmetic.

Those that failed, learned. You only see those that haven't learnt yet.

Dialog between two teachers:
T1: Oh those pupils, I told them hundred times! when will they learn?
T2: They did, but there's always new pupils.

TGIF

Uli
(wave and smile)

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: No trees in the stdlib?

2009-06-26 Thread João Valverde

Jason Scheirer wrote:

On Jun 25, 10:32 pm, [email protected] (Aahz) wrote:
  

In article ,
Tom Reed   wrote:





Why no trees in the standard library, if not as a built in? I searched
the archive but couldn't find a relevant discussion. Seems like a
glaring omission considering the batteries included philosophy,
particularly balanced binary search trees. No interest, no good
implementations, something other reason? Seems like a good fit for the
collections module. Can anyone shed some light?
  

What do you want such a tree for?  Why are dicts and the bisect module
inadequate?  Note that there are plenty of different tree implementations
available from either PyPI or the Cookbook.
--
Aahz ([email protected])   <*>http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha



...And heapq is more-or-less an emulation of a tree structure in its
underlying model. I once wrote a binary sorted tree data structure for
Python in C. It performed anywhere from 15-40% worse than dicts. I
think with optimization it will only perform 10% worse than dicts at
best.

Oh hey maybe that is why trees aren't an emphasized part of the
standard. They are going to be much slower than the ultra-optimized
dicts already in the standard lib.
  

But a dict can't be used to implement a (sorted) table ADT.
--
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread João Valverde

Stefan Behnel wrote:

João Valverde wrote:
  

Besides some interface glitches, like returning None
on delete if I recall correctly.



That's actually not /that/ uncommon. Operations that change an object are
not (side-effect free) functions, so it's just purity if they do not have a
return value.

Although practicality beats purity, sometimes... ;)

Stefan
  
I didn't know that. But in this case I think purity gets pummeled every 
time :) It's still not making sense to force a lookup to fetch something 
before deleting (another lookup operation). If that were imposed by 
python's internal machinery I'd suggest fixing that instead.


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


Re: No trees in the stdlib?

2009-06-26 Thread João Valverde

João Valverde wrote:

Stefan Behnel wrote:

João Valverde wrote:
 

Besides some interface glitches, like returning None
on delete if I recall correctly.



That's actually not /that/ uncommon. Operations that change an object 
are
not (side-effect free) functions, so it's just purity if they do not 
have a

return value.

Although practicality beats purity, sometimes... ;)

Stefan
  
I didn't know that. But in this case I think purity gets pummeled 
every time :) It's still not making sense to force a lookup to fetch 
something before deleting (another lookup operation). If that were 
imposed by python's internal machinery I'd suggest fixing that instead.


To be clear what I mean by that is that it's just reference passing so 
it can't generate programmatic errors.

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


naming packages for pypi

2009-06-26 Thread Aljosa Mohorovic
is it possible to have 2 packages with same name registered at pypi?
are packages unique per name or also per category or something else?

if package is unique per name how do you name you packages?
do you name them something like -myapp, -myapp,
-myapp, ...

if this is current situation is this something that you learned to
live with and there are no indications that this will eventually
change?

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


Re: No trees in the stdlib?

2009-06-26 Thread Chris Rebert
On Fri, Jun 26, 2009 at 12:09 AM, João Valverde wrote:
> João Valverde wrote:
>>
>> Aahz wrote:
>>>
>>> In article ,
>>> Tom Reed   wrote:
>>>

 Why no trees in the standard library, if not as a built in? I searched
 the archive but couldn't find a relevant discussion. Seems like a glaring
 omission considering the batteries included philosophy, particularly
 balanced binary search trees. No interest, no good implementations,
 something other reason? Seems like a good fit for the collections module.
 Can anyone shed some light?

>>>
>>> What do you want such a tree for?  Why are dicts and the bisect module
>>> inadequate?  Note that there are plenty of different tree implementations
>>> available from either PyPI or the Cookbook.
>>>
>>
>> A hash table is very different to a BST.  They are both useful. The bisect
>> module I'm not familiar with, I'll have to look into that, thanks.
>>
>> I have found pyavl on the web, it does the job ok, but there no
>> implementations for python3 that I know of.
>>
>> Simple example usage case: Insert string into data structure in sorted
>> order if it doesn't exist, else retrieve it.
>>
> After browsing the bisect module I don't think it is the complete answer.
> Please correct me if I'm mistaken but...
>
> Ignoring for a moment that subjectively I feel this is not very pythonic for
> my use case, if I get back the insertion position, doesn't that mean I have
> to go over on average N/2 items on a linked list to insert the item in

Linked list?! Python lists are *array-based*.
<"You must be new here" joke redacted>

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


validating HTTPS certificates?

2009-06-26 Thread Andras.Horvath
Hi,

(disclaimer: this might be a FAQ entry somewhere but I honestly did use
Google)

I'm in the process of picking a language for a client application that
accesses a HTTPS (actually SOAP) server.  This would be easy enough in
Python, but I came across a strange fact: neither httplib nor urllib
offer the possibility to actually verify the server's certificate.

After some digging I've found that from 2.6 onward, the ssl module
offers such functionality but it's not trivial, at least for me, to glue
that to the HTTP protocol modules (and then those to the SOAP module).

Did I miss something? If not, is this feature foreseen, e.g. the trivial
build-up of a HTTPS connection while verifying the certificate chain? 

thanks,

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


Re: fileinput.input, readlines and ...

2009-06-26 Thread Kushal Kumaran
On Thu, Jun 25, 2009 at 10:32 AM, Private Private wrote:
> On Jun 24, 12:23 pm, Przemyslaw Bak  wrote:
>> Hello,
>>
>> I many files with log data. The structure of the file is quite
>
> Each requested value is in separated file.
> While traversing using os.path.walk I have noticed that I get files
> unsorted.
> Is it possible to get them sorted ?
>

You can use the os.walk generator and sort the filenames in the returned tuple.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: naming packages for pypi

2009-06-26 Thread Chris Rebert
On Fri, Jun 26, 2009 at 12:54 AM, Aljosa
Mohorovic wrote:
> is it possible to have 2 packages with same name registered at pypi?
> are packages unique per name or also per category or something else?
>
> if package is unique per name how do you name you packages?
> do you name them something like -myapp, -myapp,
> -myapp, ...
>
> if this is current situation is this something that you learned to
> live with and there are no indications that this will eventually
> change?

IIRC, packages support nesting, so just do that instead. Simply put
project1..projectN into a "myapp" package and put "myapp" on PyPI.

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


Re: No trees in the stdlib?

2009-06-26 Thread João Valverde

João Valverde wrote:

João Valverde wrote:

Aahz wrote:

In article ,
Tom Reed   wrote:
 
Why no trees in the standard library, if not as a built in? I 
searched the archive but couldn't find a relevant discussion. Seems 
like a glaring omission considering the batteries included 
philosophy, particularly balanced binary search trees. No interest, 
no good implementations, something other reason? Seems like a good 
fit for the collections module. Can anyone shed some light?



What do you want such a tree for?  Why are dicts and the bisect module
inadequate?  Note that there are plenty of different tree 
implementations

available from either PyPI or the Cookbook.
  
A hash table is very different to a BST.  They are both useful. The 
bisect module I'm not familiar with, I'll have to look into that, 
thanks.


I have found pyavl on the web, it does the job ok, but there no 
implementations for python3 that I know of.


Simple example usage case: Insert string into data structure in 
sorted order if it doesn't exist, else retrieve it.


After browsing the bisect module I don't think it is the complete 
answer. Please correct me if I'm mistaken but...


Ignoring for a moment that subjectively I feel this is not very 
pythonic for my use case, if I get back the insertion position, 
doesn't that mean I have to go over on average N/2 items on a linked 
list to insert the item in position? Maybe less for sophisticated 
implementations but still O(n)? That doesn't compare favorably to the 
cost of (possibly) having to rebalance a tree on insertion.
I was indeed corrected on this shameful blunder, but in my defense array 
based lists are implementation dependent and the case for trees can be 
made on deletion.

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


Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-26 Thread Carl Banks
On Jun 25, 11:20 pm, Stefan Behnel  wrote:
> Carl Banks wrote:
> > On Jun 25, 10:11 pm, Stefan Behnel wrote:
> >> Carl Banks wrote:
>  Why isn't et.parse the only way to do this? Why have XML or fromstring  
>  at all?
> >>> Because Fredrick Lundh wanted it that way.  Unlike most Python
> >>> libraries ElementTree is under the control of one person, which means
> >>> it was not designed or vetted by the community, which means it would
> >>> tend to have some interface quirks.
> >> Just for the record: Fredrik doesn't actually consider it a design "quirk".
>
> > Well of course he wouldn't--it's his library.
>
> That's not an argument at all.

I can't even imagine what you think I was arguing when I wrote this,
or what issue you could have with this statement.


Carl Banks

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


Re: Best way to enumerate classes in a module

2009-06-26 Thread Steven D'Aprano
On Thu, 25 Jun 2009 11:30:03 -0500, Nick Craig-Wood wrote:

>>  Something makes me think that module.__dict__ was only added to Python
>>  fairly recently, but I'm not sure.
> 
> It exists in python2.1 - I don't have an older python to check at the
> moment.

$ python1.5
Python 1.5.2 (#1, Apr  1 2009, 22:55:54)  [GCC 4.1.2 20070925 (Red Hat 
4.1.2-27)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import math
>>> len(math.__dict__)
27



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


Re: naming packages for pypi

2009-06-26 Thread Carl Banks
On Jun 26, 12:54 am, Aljosa Mohorovic 
wrote:
> is it possible to have 2 packages with same name registered at pypi?
> are packages unique per name or also per category or something else?
>
> if package is unique per name how do you name you packages?
> do you name them something like -myapp, -myapp,
> -myapp, ...
>
> if this is current situation is this something that you learned to
> live with and there are no indications that this will eventually
> change?

First off, we need to distinguish between software package (a bunch of
software and other data distributed together) and Python package (a
hierarchical collection of python modules).  Furthermore some Python
packages are top-level packages, others are subpackages.

Your post seems to suggest some conflating of these concepts so you
need to make it clear what you really mean.

Usually one PyPI entry corresponds to one software package which
contains one unique top level package (which can in turn contain many
subpackages), but that's not always the case.

The main restriction is that a given top-level package may not appear
in more than one PyPI entry.  Top-level package names are unique.
(That is, unless workarounds, such as customizing the installation,
are employed.)


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


Re: Best way to enumerate classes in a module

2009-06-26 Thread Michele Simionato
On Jun 24, 7:07 pm, Terry Reedy  wrote:
> Дамјан Георгиевски wrote:
> > I need to programmaticaly enumerate all the classes in a given module.
> > Currently I'm using dir(module) but the Notice on the documentation page
> > [1]  says "dir() is supplied primarily as a convenience for use at an
> > interactive prompt" so that kind of scares me.
>
> That notice primarily refers to the fact that the special names (of
> __xxx__ form) returned are implementation and version dependent, and may
> not be complete in the sense that dir(ob) may not return __xyz__ even
> though ob.__xyz__ exists and can be retrieved.
>
> If you are only interested in regular-name attribute of ob, let your
> fear fly away.

There are rather special cases (not your case) where dir does not
retrieve
all the names to which an object can respond. In particular this
happens
for class objects:
In [1]: class C(object): pass
   ...:

In [2]: dir(C)
Out[2]:
['__class__',
 '__delattr__',
 '__dict__',
 '__doc__',
 '__getattribute__',
 '__hash__',
 '__init__',
 '__module__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__str__',
 '__weakref__']


Notice the absense of the special names __name__, __mro__,
__subclasses__ and also mro, which
is not special. All these names are defined on the metaclass type and
C responds to them,
but they are not retrieved by dir.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Steven D'Aprano
On Thu, 25 Jun 2009 12:41:13 -0600, Michael Torrie wrote:

> If you want accurate math, check out other types like what is in the
> decimal module:
> 
 import decimal
 a=decimal.Decimal('3.2')
 print a * 3
> 9.6

Not so. Decimal suffers from the exact same problem, just with different 
numbers:

>>> import decimal
>>> x = decimal.Decimal('1')/decimal.Decimal('3')
>>> 3*x == 1
False

Some numbers can't be represented exactly in base 2, and some numbers 
can't be represented exactly in base 10.


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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Steven D'Aprano
On Thu, 25 Jun 2009 12:31:05 -0700, Mark Dickinson wrote:

>> We all know that IEEE floating point is a horribly inaccurate
>> representation [...]
> 
> That's a bit extreme!  Care to elaborate?

Well, 0.1 requires an infinite number of binary places, and IEEE floats 
only have a maximum of 53 or so, so that implies that floats are 
infinitely inaccurate...

*wink*


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


Re: No trees in the stdlib?

2009-06-26 Thread Steven D'Aprano
On Fri, 26 Jun 2009 00:09:06 -0700, Jason Scheirer wrote:

> I once wrote a binary sorted tree data structure for Python in C. It
> performed anywhere from 15-40% worse than dicts. I think with
> optimization it will only perform 10% worse than dicts at best.
> 
> Oh hey maybe that is why trees aren't an emphasized part of the
> standard. They are going to be much slower than the ultra-optimized
> dicts already in the standard lib.

But dicts require hashable keys, and are in arbitrary order. You can't 
(for example) traverse a dict in post-order. 

Hash tables (dicts) are useful for many of the same things that trees are 
useful for, but they are different data structures with different 
strengths and weaknesses, and different uses. To argue that we don't need 
trees because we have dicts makes as much sense as arguing that we don't 
need dicts because we have lists.



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


seeking thru a file

2009-06-26 Thread Mag Gam
I have a compressed CSV gziped file. I was wondering if it is possible
to seek thru a file

For example:

I want to load the first 100 lines into an array. Process the data

Seek from 101 line to 200 lines. Process the data (remove lines 0 -
100) from memory

Seek 201 to 300 line. Process the data (remove 200-300)) from memory

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


Re: Reading a large csv file

2009-06-26 Thread Mag Gam
Thankyou everyone for the responses! I took some of your suggestions
and my loading sped up by 25%



On Wed, Jun 24, 2009 at 3:57 PM, Lie Ryan wrote:
> Mag Gam wrote:
>> Sorry for the delayed response. I was trying to figure this problem
>> out. The OS is Linux, BTW
>
> Maybe I'm just being pedantic, but saying your OS is Linux means little
> as there are hundreds of variants (distros) of Linux. (Not to mention
> that Linux is a kernel, not a full blown OS, and people in GNU will
> insist to call Linux-based OS GNU/Linux)
>
>> Here is some code I have:
>> import numpy as np
>> from numpy import *
>
> Why are you importing numpy twice as np and as *?
>
>> import gzip
>> import h5py
>> import re
>> import sys, string, time, getopt
>> import os
>>
>> src=sys.argv[1]
>> fs = gzip.open(src)
>> x=src.split("/")
>> filename=x[len(x)-1]
>>
>> #Get /MM/DD format
>> =(filename.rsplit(".",2)[0])[0:4]
>> MM=(filename.rsplit(".",2)[0])[4:6]
>> DD=(filename.rsplit(".",2)[0])[6:8]
>
>>
>> f=h5py.File('/tmp/test_foo/FE.hdf5','w')
>
> this particular line would make it impossible to have more than one
> instance of the program open. May not be your concern...
>
>>
>> grp="/"+
>> try:
>>   f.create_group(grp)
>> except ValueError:
>>   print "Year group already exists"
>>
>> grp=grp+"/"+MM
>> try:
>>   f.create_group(grp)
>> except ValueError:
>>   print "Month group already exists"
>>
>> grp=grp+"/"+DD
>> try:
>>   group=f.create_group(grp)
>> except ValueError:
>>   print "Day group already exists"
>>
>
>> str_type=h5py.new_vlen(str)
>
>> mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1',
>> 'f4', 'f4')}
>> print "Filename is: ",src
>> fs = gzip.open(src)
>
>> dset = f.create_dataset ('Foo',data=arr,compression='gzip')
>
> What is `arr`?
>
>> s=0
>>
>> #Takes the longest here
>> for y in fs:
>>      continue
>>   a=y.split(',')
>
>>   s=s+1
>>   dset.resize(s,axis=0)
>
> You increment s by 1 for each iteration, would this copy the dataset? (I
> never worked with h5py, so I don't know how it works)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extending method descriptors

2009-06-26 Thread Michael Sliczniak
On Jun 25, 2:30 pm, Carl Banks  wrote:

Thank you for the very good reply. In fact delegating is the approach
that works. The main thing to notice is that for an uninstantiated
class the first arg to __get__ is None:

class desc(object):
__slots__ = ('x')

def __init__(self, desc):
self.x = desc

def __get__(self, a, b):
#print 'desc get', `self`, `a`, `b`

if a == None:
return self

return self.x.__get__(a)

def __set__(self, a, b):
#print 'desc set', `self`, `a`, `b`

self.x.__set__(a, b)

def foo(self):
return 'foo'

def bar(self):
return 'bar'

class A(object):
__slots__ = ('x', 'y')
def __init__(self, *args):
for i in xrange(len(args)):
setattr(self, A.__slots__[i], args[i])

a = A(0, 1)
b = A(2, 3)

print a.x, a.y, b.x, b.y

x = A.x
dx = desc(x)
A.x = dx

y = A.y
dy = desc(y)
A.y = dy

print type(a).x.foo()
print type(a).x.bar()
print type(a).y.foo()
print type(a).y.bar()
print type(b).x.foo()
print type(b).x.bar()
print type(b).y.foo()
print type(b).y.bar()

print a.x, a.y, b.x, b.y

a.x = -1
a.y = -2
b.x = -3
b.y = -4

print a.x, a.y, b.x, b.y

A.x = x

print a.x, a.y, b.x, b.y

This produces this output:

0 1 2 3
foo
bar
foo
bar
foo
bar
foo
bar
0 1 2 3
-1 -2 -3 -4
-1 -2 -3 -4

The manner in which __get__ has to delegate is not pleasant compared
to if you could simply derive a new class from method_descriptor with
the foo and bar methods though, oh well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread Paul Rubin
Stefan Behnel  writes:
> > Besides some interface glitches, like returning None
> > on delete if I recall correctly.
> 
> That's actually not /that/ uncommon. Operations that change an object are
> not (side-effect free) functions, so it's just purity if they do not have a
> return value.

But deletes in an AVL tree should not cause mutation.  They should
just allocate a new root and path up to where the deleted node was.
That allows having references to the old and new versions of the tree,
etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread Paul Rubin
Chris Rebert  writes:
> > Simple example usage case: Insert string into data structure in
> > sorted order if it doesn't exist, else retrieve it.
> 
> That's pretty much the bisect module in a nutshell. It manipulates a
> sorted list using binary search.

That lets you find an existing entry in log(n) time, but inserting
or deleting an entry still takes linear time.  Also, you don't
get a persistent structure in the sense of functional programming.

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


Re: No trees in the stdlib?

2009-06-26 Thread Stefan Behnel
Paul Rubin wrote:
> Stefan Behnel writes:
>>> Besides some interface glitches, like returning None
>>> on delete if I recall correctly.
>> That's actually not /that/ uncommon. Operations that change an object are
>> not (side-effect free) functions, so it's just purity if they do not have a
>> return value.
> 
> But deletes in an AVL tree should not cause mutation.  They should
> just allocate a new root and path up to where the deleted node was.
> That allows having references to the old and new versions of the tree,
> etc.

I doubt that there are many AVL implementations that do that. Plus, if
deletion doesn't delete, I'd happily consider that a bug.

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


file transfer in python

2009-06-26 Thread jayesh bhardwaj
i am trying to find something useful in python to transfer html files
from one terminal to other. Can this be done with some module or shall
i start coding my own module using low level socket interface. If u
know about some books on this topic or any online help then plz help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: It's ...

2009-06-26 Thread Angus Rodgers
On Thu, 25 Jun 2009 18:22:48 +0100, MRAB 
 wrote:

>Angus Rodgers wrote:
>> On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser 
>>  wrote:
>> 
>>> At 2009-06-24T19:53:49Z, Angus Rodgers  writes:
>>>
 print ''.join(map(detab, f.xreadlines()))
>>> An equivalent in modern Pythons:
>>>
>> print ''.join(line.expandtabs(3) for line in file('h071.txt'))
>> 
>> I guess the code below would also have worked in 2.1?
>> (It does in 2.5.4.)
>> 
>>  print ''.join(line.expandtabs(3) for line in \
>>  file('h071.txt').xreadlines())
>> 
>That uses a generator expression, which was introduced in 2.4.

Sorry, I forgot that list comprehensions need square brackets.

The following code works in 2.1 (I installed version 2.1.3, on
a different machine, to check!):

 f = open('h071.txt')   # Can't use file('h071.txt') in 2.1
 print ''.join([line.expandtabs(3) for line in f.xreadlines()])

(Of course, in practice I'll stick to doing it the more sensible
way that's already been explained to me.  I'm ordering a copy of
Wesley Chun, /Core Python Programming/ (2nd ed., 2006), to learn
about version 2.5.)
-- 
Angus Rodgers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file transfer in python

2009-06-26 Thread Doron Tal
On Fri, Jun 26, 2009 at 2:38 PM, jayesh bhardwaj
wrote:

> i am trying to find something useful in python to transfer html files
> from one terminal to other. Can this be done with some module or shall
> i start coding my own module using low level socket interface. If u
> know about some books on this topic or any online help then plz help.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You can try the xmlrpclib:
http://docs.python.org/library/xmlrpclib.html#binary-objects

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


Re: file transfer in python

2009-06-26 Thread Francesco Bochicchio
On 26 Giu, 13:38, jayesh bhardwaj  wrote:
> i am trying to find something useful in python to transfer html files
> from one terminal to other. Can this be done with some module or shall
> i start coding my own module using low level socket interface. If u
> know about some books on this topic or any online help then plz help.

In the standard library there is ftplib, which allows your program to
act as a FTP client. Of course
the receiver end should have an FTP server installing and running. I
don't tink it can handle SFTP protocol, so
if you are concerned with security you should opt for someting else,
or protect your connection somehow (e.g. SSH tunneling).

Or, if you have ssh (client and server) installed, you could simply
spawn a subprocess ( see the subprocess module for that ) which
execute one or more 'scp' commands.

Ciao

FB

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


Re: Python simple web development

2009-06-26 Thread bijoy franco
Hi,
I am learning pylons..It seems to be very simple and flexible..

Just give a try if it seems interesting for you

Thanks

Bijoy

On Fri, Jun 26, 2009 at 3:02 AM, Gabriel Genellina
wrote:

> En Thu, 25 Jun 2009 04:29:28 -0300, Private Private 
> escribió:
>
>  I am looking for a python library which will allow me to do a simple
>> web development. I need to use
>> some forms (but nice looking :-) ), creating images based on input
>> from those forms, etc. I have read a bit about Django and TurboGears
>> but I am afraid that this is too big for my requirements (am I
>> wrong ?).
>> Can you suggest anything ?
>>
>
> You may try pesto: http://pesto.redgecko.org/
>
> pesto is a very small framework (45k to download!), WSGI compliant,
> includes session management, mapping URL->function, caching, templates
> (optional, whichever you like). Minimalist but flexible.
>
> Anyway, learning to use Django isn't a bad idea.
>
> --
> Gabriel Genellina
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: seeking thru a file

2009-06-26 Thread Nils Rüttershoff
Hi Mag,

Mag Gam wrote:
> I have a compressed CSV gziped file. I was wondering if it is possible
> to seek thru a file
>
> For example:
>
> I want to load the first 100 lines into an array. Process the data
>
> Seek from 101 line to 200 lines. Process the data (remove lines 0 -
> 100) from memory
>
> Seek 201 to 300 line. Process the data (remove 200-300)) from memory
>
> etc..etc..
>   

This would be very easy. Here is one way you could do it:
(I didn't test the code; I've just write it down, assuming you use
python 2.6, cause you didn't mentioned which version you are using...)

import gzip

step = 100
data_present = True
with gzip.open(foo.csv.gzip) as my_file:
counter = 0
my_buffer = []
while data_present:
while counter <= step:
line = my_file.readline()
if line:
my_buffer.append(my_file.readline())
counter += 1
else:
data_present = False
break
if len(my_buffer) > 0:
do_something(my_buffer)
counter = 0
my_buffer = []


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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Sebastian Pająk
2009/6/26 norseman :
> Sebastian Pająk wrote:
>>>
>>> Can, but should not.
>>> I read that the problem is when using the Polish language only. Otherwise
>>> things work normally. Is that correct?
>>
>> Yes, correct
>>
>>> If so then byte swap may be a problem.  Using the u'string' should solve
>>> that. I am assuming you have the Polish alphabet working correctly on
>>> your
>>> machine. I think I read that was so in an earlier posting.
>>>
>>> Are there any problems with his alphabet scrambling on your machine?
>>> If so that needs investigating.  Here I assume you are reading Polish
>>> from
>>> him on your machine and not a network translator version.
>>>
>>
>> The original thread is here:
>> http://mail.python.org/pipermail/python-list/2009-June/717666.html
>> I've explained the problem there
>
> 
> I re-read the posting. (Thanks for the link)
>
> You do not mention if he has sent you any Polish words and if they
> appear OK on your machine.
>

He has sent my a polish words, they appear correct. We both have the
english version of systems (they are both set to polish locale (time,
dates, keyboard etc.))

> A note here:  In reading the original posting I get symbols that are not
> familiar to me as alphabet.
> From the line in your original:
>     Label(root, text='ęóąśłżźćń').pack()
> I see text='
>           then an e with a goatee
>                a  capitol O with an accent symbol on top (')
>                an a with a tail on the right
>                a  s with an accent on top
>                an I do no not know what - maybe some sort of l with a
>                                           slash through the middle
>                a  couple of z with accents on top
>                a  capitol C with an accent on top
>                a  n with a short bar on top
>
> I put the code into python and took a look.
>
>
>
> I get:
> cat xx
>
> # -*- coding: utf-8 -*-
>
> import sys
> from Tkinter import *
>
> root = Tk()
>
> Label(root, text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
> Button(root,
> text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
> Entry(root).pack()
>
> root.mainloop()
>
> Then:
> python xx
>  File "xx", line 10
> SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no
> encoding declared; see http://www.python.org/peps/pep-0263.html for details
>
> So I did.
> It notes Window$ puts things into those lines. Namely:
> "To aid with platforms such as Windows, which add Unicode BOM marks
>    to the beginning of Unicode files, the UTF-8 signature
>    '\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well
>    (even if no magic encoding comment is given).
> "
>
> Then I took out the o with the accent and re-ran the file.
>
> Everything works except the text is exactly as shown above. That is:
> \u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144
> (shows twice as directed, one for label, one for button, no apostrophes)
>
> OK - now I take a look at what in actually in the file.
> in MC on Linux Slackware 10.2 I read, in the mail folder,
> 0119 capitol A with a tilde on top.
> HEX readings beginning at the 0119\...
> 30 31 31 39 C3 B3 5C
>
> but in the python file xx, I read:
> 30 31 31 39 5C
> 0119\...
>
> I would have to say the mail system is screwing you up.  Might try zipping
> the file and sending it that way and see if problem changes.
>

I've tried zipping
It looks like you you didn't save the script in UTF-8. Try to run the
original script file from attachment (UTF-8 without BOM).
ps. Do you have mac os x? It would be better if someone with mac tested it


# -*- coding: utf-8 -*-

import sys

from Tkinter import *

root = Tk()
root.tk.call('encoding', 'system', 'utf-8')

Label(root, text=u'ęóąśłżźćń').pack()
Button(root, text=u'ęóąśłżźćń').pack()

root.mainloop()


test1.py
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: seeking thru a file

2009-06-26 Thread Bruno Desthuilliers

Mag Gam a écrit :
I have a compressed CSV gziped file. 


Then gunzip it first...


I was wondering if it is possible
to seek thru a file

For example:

I want to load the first 100 lines into an array. Process the data

Seek from 101 line to 200 lines. Process the data (remove lines 0 -
100) from memory

Seek 201 to 300 line. Process the data (remove 200-300)) from memory

etc..etc..


Yes, you can... Now is there any reason you want to micro-manage stuff 
already managed by Python and the file system ?-)


To iterate on a text file's lines, just open the file - the file object 
is it's own iterator, and will (with help from the filesystem AFAIK) 
properly handle cache, buffers and whatnot. The canonical code snippet is:


# iterating over a file line by line without
# loading the while file in memory
f = open("/path/to/some/file.txt")
for line in f:
do_something_with(line)

f.close()


Unless you have a good reason (micro-managing IO buffers not being one) 
to want to work by 100-lines batch, then this should be just enough.


Now note that Python also have a csv module in the standard lib, which 
will probably (except perhaps in a very few corner cases) be more robust 
and efficient that whatever you'd write.



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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Sebastian Pająk
>  in place where polish
>> accented character should be (like "ęłąśł" etc)
>> This problem is only on mac os x and it doesn't apply to button widget
>> (where characters are correct)
>
> I see. So it is a font problem: if the square box is displayed, it means
> that the font just doesn't have a glyph for the character you want to
> display. Try using a different font in the label widget.

I've tried many fonts, the effect is always the same. Standard fonts
like Arial, Tahoma, Vedana all have Polish glyphs. The problem is that
Tkinter selects wrong glyphs for non-ASCII chars. It's not the font
issue as text on Button widget appears correctly

>> There is no wish. I'm talking about build-in Tkinter
>
> So try installing Tk separately.
>
>> (isn't Tk build-in Python?).
>
> Depends on where exactly you got your Python from, and what exactly
> is your OSX version. Recent releases of OSX include a copy of Tcl/Tk,
> and some sets of Python binaries link against the Apple Tk.
>

As I said I don't have mac osx. I just expect my Python script to be
portable and behave the same on both Windows and OSX, but It isn't.
-- 
http://mail.python.org/mailman/listinfo/python-list


Py 3 slower than Py 2. Towers of Hanoi implementation

2009-06-26 Thread Udyant Wig
I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in
both flavors of Python: 2.6.2 and 3.0.1 (CPython)

The code:
#!/usr/bin/env python
def remaining_peg (peg1, peg2):
return (6 - peg1 - peg2)

def hanoi (num_discs, start, end):
if (1 == num_discs):
print "Top of peg {0} to peg {1}".format(start,end) # used 
print()
for Py 3.0.1

else:
hanoi ((num_discs - 1), start, (remaining_peg (start, end)))
hanoi (1, start, end)
hanoi ((num_discs - 1), (remaining_peg (start, end)), end)


hanoi(20,2,3)

The times:real  usr  sys
Python 2.6.2   7.994s3.336s   3.296s
Python 3.0.1   55.302s  38.024s 5.876s

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread pdpi
On Jun 26, 11:01 am, Steven D'Aprano  wrote:
> On Thu, 25 Jun 2009 12:41:13 -0600, Michael Torrie wrote:
> > If you want accurate math, check out other types like what is in the
> > decimal module:
>
>  import decimal
>  a=decimal.Decimal('3.2')
>  print a * 3
> > 9.6
>
> Not so. Decimal suffers from the exact same problem, just with different
> numbers:
>
> >>> import decimal
> >>> x = decimal.Decimal('1')/decimal.Decimal('3')
> >>> 3*x == 1
>
> False
>
> Some numbers can't be represented exactly in base 2, and some numbers
> can't be represented exactly in base 10.
>
> --
> Steven

But since 10 = 2 * 5, all numbers that can be finitely represented in
binary can be represented finitely in decimal as well, with the exact
same number of  places for the fractional part (and no more digits
than the binary representation in the integer part)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py 3 slower than Py 2. Towers of Hanoi implementation

2009-06-26 Thread Stefan Behnel
Udyant Wig wrote:
> I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in
> both flavors of Python: 2.6.2 and 3.0.1 (CPython)
> 
> The code:
> #!/usr/bin/env python
> def remaining_peg (peg1, peg2):
>   return (6 - peg1 - peg2)
> 
> def hanoi (num_discs, start, end):
>   if (1 == num_discs):
>   print "Top of peg {0} to peg {1}".format(start,end) # used 
> print()
> for Py 3.0.1
> 
>   else:
>   hanoi ((num_discs - 1), start, (remaining_peg (start, end)))
>   hanoi (1, start, end)
>   hanoi ((num_discs - 1), (remaining_peg (start, end)), end)
> 
> 
> hanoi(20,2,3)
> 
> The times:real  usr  sys
> Python 2.6.2   7.994s3.336s   3.296s
> Python 3.0.1   55.302s  38.024s 5.876s
> 
> What happened to Python?

Have you tried Python 3.1? Have you made sure that both Python interpreters
were build with the same compiler arguments and that none of them is a
debug build?

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


Re: No trees in the stdlib?

2009-06-26 Thread Hallvard B Furuseth
Stefan Behnel writes:
>João Valverde wrote:
>> Besides some interface glitches, like returning None
>> on delete if I recall correctly.
>
> That's actually not /that/ uncommon. Operations that change an object are
> not (side-effect free) functions, so it's just purity if they do not have a
> return value.

It's purity that they don't return the modified tree/dict/whatever.
They can still return the deleted element and remain pure.

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


Re: Py 3 slower than Py 2. Towers of Hanoi implementation

2009-06-26 Thread Udyant Wig
On Jun 26, 7:14 pm, Stefan Behnel  wrote:
> Udyant Wig wrote:
> > I implemented this ->http://www.apl.jhu.edu/~hall/lisp/Hanoi.lispin
> > both flavors of Python: 2.6.2 and 3.0.1 (CPython)
>
> > The code:
> > #!/usr/bin/env python
> > def remaining_peg (peg1, peg2):
> >    return (6 - peg1 - peg2)
>
> > def hanoi (num_discs, start, end):
> >    if (1 == num_discs):
> >            print "Top of peg {0} to peg {1}".format(start,end) # used 
> > print()
> > for Py 3.0.1
>
> >    else:
> >            hanoi ((num_discs - 1), start, (remaining_peg (start, end)))
> >            hanoi (1, start, end)
> >            hanoi ((num_discs - 1), (remaining_peg (start, end)), end)
>
> > hanoi(20,2,3)
>
> > The times:            real          usr          sys
> > Python 2.6.2       7.994s    3.336s   3.296s
> > Python 3.0.1       55.302s  38.024s 5.876s
>
> > What happened to Python?
>
> Have you tried Python 3.1? Have you made sure that both Python interpreters
> were build with the same compiler arguments and that none of them is a
> debug build?
>
> Stefan

Yes. Both were built with the same compiler parameters.
No. None of them is a debug build.
I'm currently getting Python 3.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread Stefan Behnel
Hallvard B Furuseth wrote:
> Stefan Behnel writes:
>> João Valverde wrote:
>>> Besides some interface glitches, like returning None
>>> on delete if I recall correctly.
>> That's actually not /that/ uncommon. Operations that change an object are
>> not (side-effect free) functions, so it's just purity if they do not have a
>> return value.
> 
> It's purity that they don't return the modified tree/dict/whatever.
> They can still return the deleted element and remain pure.

Fair enough.

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Scott David Daniels

pdpi wrote:

... But since 10 = 2 * 5, all numbers that can be finitely represented in
binary can be represented finitely in decimal as well, with the exact
same number of  places for the fractional part (and no more digits
than the binary representation in the integer part)


OK, so base 30 is the obvious choice, digits and letters, and 1/N works
for n in range(1, 7) + range(8, 11).  Gödel numbers, anyone? :-)

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


"The system cannot execute the specified program."

2009-06-26 Thread Tim Slattery
Our office has a copy of Python 3.0 installed on a network share
device. When I try to run it I get this message: "The system cannot
execute the specified program."

When I googled that message, the links that came up had to do with
missing DLLs. So I fired up Dependency Walker and found out that there
were indeed DLLs that it needed that the OS couldn't find. So I
supplied those DLLs. And it still gives the same message, even though
Dependency Walker is now happy.

Does anybody have a clue what might cause this amazingly uninformative
message?

On a related note: there's a *.chm file on the same share, that's a
PYthon user's guide. When I start that, I get a window with the full
table of contents and index on the left side. But on the right side
where the contents should be ... "Navigation to the web page was
canceled". WTF???

-- 
Tim Slattery
[email protected]
http://members.cox.net/slatteryt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py 3 slower than Py 2. Towers of Hanoi implementation

2009-06-26 Thread Paul Moore
2009/6/26 Udyant Wig :
> I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in
> both flavors of Python: 2.6.2 and 3.0.1 (CPython)
>
> The code:
> #!/usr/bin/env python
> def remaining_peg (peg1, peg2):
>        return (6 - peg1 - peg2)
>
> def hanoi (num_discs, start, end):
>        if (1 == num_discs):
>                print "Top of peg {0} to peg {1}".format(start,end) # used 
> print()
> for Py 3.0.1
>
>        else:
>                hanoi ((num_discs - 1), start, (remaining_peg (start, end)))
>                hanoi (1, start, end)
>                hanoi ((num_discs - 1), (remaining_peg (start, end)), end)
>
>
> hanoi(20,2,3)
>
> The times:            real          usr          sys
> Python 2.6.2       7.994s    3.336s   3.296s
> Python 3.0.1       55.302s  38.024s 5.876s
>
> What happened to Python?

I/O in Python 3.0 is known to be slow, because the bulk of the
implementation is in Python (rather than C). Python 3.1 addresses
this. Here are some tests of 2.6.1 vs 3.1rc2. The first tests have the
print commented out, the second are with the print, redirected to the
null device. The tests are on a pretty slow Windows XP SP2 laptop.

>timer & \Apps\Python26\python.exe hanoi.py & timer
Timer 1 on: 15:54:53
Timer 1 off: 15:54:57  Elapsed: 0:00:03.88

>timer & \Apps\Python31\python.exe hanoi.py & timer
Timer 1 on: 15:57:05
Timer 1 off: 15:57:09  Elapsed: 0:00:03.67

>timer & (\Apps\Python26\python.exe hanoi.py >nul) & timer
Timer 1 on: 15:57:44
Timer 1 off: 15:58:14  Elapsed: 0:00:29.91

>timer & (\Apps\Python31\python.exe hanoi.py >nul) & timer
Timer 1 on: 15:58:38
Timer 1 off: 15:59:09  Elapsed: 0:00:30.63

Nothing much in it.

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


Re: naming packages for pypi

2009-06-26 Thread Aljosa Mohorovic
On Jun 26, 11:15 am, Carl Banks  wrote:
> Your post seems to suggest some conflating of these concepts so you
> need to make it clear what you really mean.

my example:
when creating website example.com (django project) it contains
multiple django apps which i package separately.
most of websites have news, about, contact so i would create 3
packages news, about and contact and add them to pypi.example.com
(private pypi for my company).
same thing happens for site example2.com, example3.com so finally i
have something like:
example.com-news # news package for project/site example.com
example2.com-news # news package for project/site example2.com
example3.com-news # news package for project/site example3.com

i'm trying to find a better way, currently it looks to me like
packaging system is missing namespaces/categories or something similar
but i'm guessing it's only that i don't know how to do it properly.
that's why i'm asking so please suggest a proper way for me to do it.

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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Andre Engels
On Fri, Jun 26, 2009 at 5:07 PM, Scott David
Daniels wrote:
> pdpi wrote:
>>
>> ... But since 10 = 2 * 5, all numbers that can be finitely represented in
>> binary can be represented finitely in decimal as well, with the exact
>> same number of  places for the fractional part (and no more digits
>> than the binary representation in the integer part)
>
> OK, so base 30 is the obvious choice, digits and letters, and 1/N works
> for n in range(1, 7) + range(8, 11).  Gödel numbers, anyone? :-)

To get even more working, use real rational numbers: p/q represented
by the pair of numbers (p,q) with p,q natural numbers. Then 1/N works
for every N, and upto any desired precision.


-- 
André Engels, [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recipes for trace statements inside python programs?

2009-06-26 Thread cassiope
On Jun 25, 1:33 am, Francesco Bochicchio  wrote:
> Hi all,
>
> as many - I think - python programmers, I find muself debugging my
> scripts by placing print statements in strategic places rather than
> using the python debugger, and commenting/uncommenting them according
> to myy deugging needs.  After a time, these prints staements start to
> evolving in some ad-hoc half-baked framework ... so I wonder if there
> is somewhere there is a full-baked trace statement support framework
> which I can use. I'm aware of the logging module, but for me it its
> more geared toward  application logging rather than toward trace for
> debugging purpose.
>
> Having googlet and found nothing (or too much but nothing relefìvant),
> I'm now asking The List.
>
> Here is what I have in mind:
>
> Each module, function, class and method should have an attribute, say
> trace_flag, which can be set to true or false value.
>
> there should be a function TRACE which does something like this:
>
> if __debug__ :
> def TRACE(*args):
>      if  trace_enabled(): print "TRACE(%s) : %s " % ( context(), "
> ".join( str(x) for x in args ) )
>
> where trace_enabled() should return the value of the innermost
> trace_flag (checking current function/method then current class (if
> any) then current module) and context() shoud return a string like
> "module.function" or "module.class.method" ).
>
> At this point I could in my test code enable  the trace in the
> function/class that gives me trouble and disable it after I fixed it,
> without having to touch the actual code under test.
>
> I guess it should not be too hard do using python introspection
> modules, but of couse I first would like to know if something like
> this already exists.
>
> I'm  aware that this imposes a performance penalty, but my scripts are
> not operformance-critical. And if I put an if __debug__ switch

What are you trying to achieve that could not be accomplished with
the logging module?

   http://docs.python.org/library/logging.html#module-logging

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


Re: "The system cannot execute the specified program."

2009-06-26 Thread Tim Golden

Tim Slattery wrote:

Our office has a copy of Python 3.0 installed on a network share
device. When I try to run it I get this message: "The system cannot
execute the specified program."


To be honest, I'd look at one of the Portable Python installations,
specifically designed to be run off a stick or a network share.


 http://www.portablepython.com/

 http://www.voidspace.org.uk/python/movpy/


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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Sebastian Pająk
Maybe this picture will tell you more:
http://files.getdropbox.com/u/1211593/tkinter.png

The original script:
http://files.getdropbox.com/u/1211593/test1.py

May someone can confirm this osx behaviour?


2009/6/26 Sebastian Pająk :
> 2009/6/26 norseman :
>> Sebastian Pająk wrote:

 Can, but should not.
 I read that the problem is when using the Polish language only. Otherwise
 things work normally. Is that correct?
>>>
>>> Yes, correct
>>>
 If so then byte swap may be a problem.  Using the u'string' should solve
 that. I am assuming you have the Polish alphabet working correctly on
 your
 machine. I think I read that was so in an earlier posting.

 Are there any problems with his alphabet scrambling on your machine?
 If so that needs investigating.  Here I assume you are reading Polish
 from
 him on your machine and not a network translator version.

>>>
>>> The original thread is here:
>>> http://mail.python.org/pipermail/python-list/2009-June/717666.html
>>> I've explained the problem there
>>
>> 
>> I re-read the posting. (Thanks for the link)
>>
>> You do not mention if he has sent you any Polish words and if they
>> appear OK on your machine.
>>
>
> He has sent my a polish words, they appear correct. We both have the
> english version of systems (they are both set to polish locale (time,
> dates, keyboard etc.))
>
>> A note here:  In reading the original posting I get symbols that are not
>> familiar to me as alphabet.
>> From the line in your original:
>>     Label(root, text='ęóąśłżźćń').pack()
>> I see text='
>>           then an e with a goatee
>>                a  capitol O with an accent symbol on top (')
>>                an a with a tail on the right
>>                a  s with an accent on top
>>                an I do no not know what - maybe some sort of l with a
>>                                           slash through the middle
>>                a  couple of z with accents on top
>>                a  capitol C with an accent on top
>>                a  n with a short bar on top
>>
>> I put the code into python and took a look.
>>
>>
>>
>> I get:
>> cat xx
>>
>> # -*- coding: utf-8 -*-
>>
>> import sys
>> from Tkinter import *
>>
>> root = Tk()
>>
>> Label(root, text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
>> Button(root,
>> text='\u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack()
>> Entry(root).pack()
>>
>> root.mainloop()
>>
>> Then:
>> python xx
>>  File "xx", line 10
>> SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no
>> encoding declared; see http://www.python.org/peps/pep-0263.html for details
>>
>> So I did.
>> It notes Window$ puts things into those lines. Namely:
>> "To aid with platforms such as Windows, which add Unicode BOM marks
>>    to the beginning of Unicode files, the UTF-8 signature
>>    '\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well
>>    (even if no magic encoding comment is given).
>> "
>>
>> Then I took out the o with the accent and re-ran the file.
>>
>> Everything works except the text is exactly as shown above. That is:
>> \u0119ó\u0105\u015b\u0142\u017c\u017a\u0107\u0144
>> (shows twice as directed, one for label, one for button, no apostrophes)
>>
>> OK - now I take a look at what in actually in the file.
>> in MC on Linux Slackware 10.2 I read, in the mail folder,
>> 0119 capitol A with a tilde on top.
>> HEX readings beginning at the 0119\...
>> 30 31 31 39 C3 B3 5C
>>
>> but in the python file xx, I read:
>> 30 31 31 39 5C
>> 0119\...
>>
>> I would have to say the mail system is screwing you up.  Might try zipping
>> the file and sending it that way and see if problem changes.
>>
>
> I've tried zipping
> It looks like you you didn't save the script in UTF-8. Try to run the
> original script file from attachment (UTF-8 without BOM).
> ps. Do you have mac os x? It would be better if someone with mac tested it
>
>
> # -*- coding: utf-8 -*-
>
> import sys
>
> from Tkinter import *
>
> root = Tk()
> root.tk.call('encoding', 'system', 'utf-8')
>
> Label(root, text=u'ęóąśłżźćń').pack()
> Button(root, text=u'ęóąśłżźćń').pack()
>
> root.mainloop()
>
-- 
http://mail.python.org/mailman/listinfo/python-list


R-tree implemetation in python without external C_libraries

2009-06-26 Thread News123
Hi,

I'd like to have a small rtree library for a small python project.
( good data structure for 2D searches )

For this mini - project I'd prefer, to have no C-library dependencies

Does anyone have a small implementation which I'm allowed to use and
modify, which does not use an external C-library?


What I'm mostly interested in is the R-Tree creation.
Thanks in advance for any pointers.

If you don't know a pure python implementation, then I'd be also
interested in implemetations in other languages.
I could then use these implementations and recode them to python.

The alternative languages could be

perl
java
java-script
C
C++
thanks in advance for any pointers

bye


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


opening a https web page

2009-06-26 Thread Addy
Dear sir,
  i am not being able to open "https://"; web pages using
urllib2 or urllib. I am being able to open "http" pages though. i am
connecting the internet through a proxy server. I am being able to
open "https://"; pages if i am using an ineternet connection that does
not connect through a proxy server.Please Help.
Looking forward to your reply.

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


handling https sites

2009-06-26 Thread padfoot
Sir,
 Is there any module in python to open https sites through a
proxy.I am connectyed to the net via a proxy server and i am unable to
crawl https sites.
-- 
http://mail.python.org/mailman/listinfo/python-list


MultiValueDict?

2009-06-26 Thread BarakatX2
, ,
]}>

for f in files['rqFiles']:
print f.name

This gives me an "'str' object has no attribute 'name'" error. I don't
know if there is a special way to access MultiValueDicts values, but I
assumed each key has a list that is accessed just like any other list.
Any help is appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: handling https sites

2009-06-26 Thread Shawn Milochik


On Jun 26, 2009, at 12:08 PM, padfoot wrote:


Sir,
Is there any module in python to open https sites through a
proxy.I am connectyed to the net via a proxy server and i am unable to
crawl https sites.
--
http://mail.python.org/mailman/listinfo/python-list


Check out the "Scrape the Web" series from the 2009 PyCon:

http://advocacy.python.org/podcasts/


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


Re: handling https sites

2009-06-26 Thread cgoldberg
> Is there any module in python to open https
> sites through a proxy.

yes, you can use "urllib2".

from the urllib2 docs:
"The default is to read the list of proxies from the environment
variables"

So if you have a proxy setup, it should detect it from your
environment vars.  If you want to specify something different, you
want to build an opener with a ProxyHandler:

http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler

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


Re: "The system cannot execute the specified program."

2009-06-26 Thread Tim Slattery
Tim Slattery  wrote:

>Our office has a copy of Python 3.0 installed on a network share
>device. When I try to run it I get this message: "The system cannot
>execute the specified program."

I should add that before I knew about our shared installation, I
downloaded the AS distribution of Python 2.6 from ActiveState. Their
install procedure is a *.bat file that calls Python to put everything
in the right place. When the bat file tries to invoke Python, I get
the same message.

-- 
Tim Slattery
[email protected]
http://members.cox.net/slatteryt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "The system cannot execute the specified program."

2009-06-26 Thread Duncan Booth
Tim Slattery  wrote:

> Our office has a copy of Python 3.0 installed on a network share
> device. When I try to run it I get this message: "The system cannot
> execute the specified program."
> 
> When I googled that message, the links that came up had to do with
> missing DLLs. So I fired up Dependency Walker and found out that there
> were indeed DLLs that it needed that the OS couldn't find. So I
> supplied those DLLs. And it still gives the same message, even though
> Dependency Walker is now happy.
> 
> Does anybody have a clue what might cause this amazingly uninformative
> message?

Are you using Vista? There seem to be some strange security settings for 
network shares in Vista. I had a file shared from an XP system which my 
Vista system could not access even though other machines could access it. 
Eventually I had to copy the file from the XP machine onto the Vista 
machine and it was happy to access it once it was on the local system.

Alternatively for a non-Vista wild guess, could it be that Python 3.0 is 
loading some libraries that use .Net and is therefore triggering the 'code 
access security' which prevents the running of .Net applications from a 
network share?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: validating HTTPS certificates?

2009-06-26 Thread Nobody
On Fri, 26 Jun 2009 10:04:21 +0200, Andras.Horvath wrote:

> (disclaimer: this might be a FAQ entry somewhere but I honestly did use
> Google)
> 
> I'm in the process of picking a language for a client application that
> accesses a HTTPS (actually SOAP) server.  This would be easy enough in
> Python, but I came across a strange fact: neither httplib nor urllib
> offer the possibility to actually verify the server's certificate.
> 
> After some digging I've found that from 2.6 onward, the ssl module
> offers such functionality but it's not trivial, at least for me, to glue
> that to the HTTP protocol modules (and then those to the SOAP module).
> 
> Did I miss something? If not, is this feature foreseen, e.g. the trivial
> build-up of a HTTPS connection while verifying the certificate chain? 

For a urllib-style interface, there's not much point in performing
verification after the fact. Either the library performs verification or
it doesn't. If it doesn't, you've just sent the (potentially confidential)
request to an unknown server; discovering this after the fact doesn't
really help.

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


Re: No trees in the stdlib?

2009-06-26 Thread Paul Rubin
Stefan Behnel  writes:
> > But deletes in an AVL tree should not cause mutation.  They should
> > just allocate a new root and path up to where the deleted node was.
> I doubt that there are many AVL implementations that do that. Plus, if
> deletion doesn't delete, I'd happily consider that a bug.

I've never seen one that DIDN'T do that, but maybe it's just the crowd
I hang out with.

See "Purely Functional Data Structures" by Chris Okasaki for more
detailed descriptions of such methods.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread Aahz
In article <[email protected]>,
Steven D'Aprano   wrote:
>
>Hash tables (dicts) are useful for many of the same things that trees are 
>useful for, but they are different data structures with different 
>strengths and weaknesses, and different uses. To argue that we don't need 
>trees because we have dicts makes as much sense as arguing that we don't 
>need dicts because we have lists.

The problem is that trees are like standards: there are so many to choose
from.  Each has its own tradeoffs, and because Python dicts and lists can
substitute for many of the traditionals uses of trees, the tradeoffs are
less clear.  I think nobody would object to adding trees to the standard
library, but it will certainly require a clear PEP, preferably with a
pointer to an existing PyPI library that has acquired real-world use.

(In particular, WRT the bisect module, although insertion and deletion
are O(N), the constant factor for doing a simple memory move at C speed
swamps bytecode until N gets very large -- and we already have
collections.deque() for some other common use cases.)
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py 3 slower than Py 2. Towers of Hanoi implementation

2009-06-26 Thread Udyant Wig
On Jun 26, 8:01 pm, Paul Moore  wrote:
> 2009/6/26 Udyant Wig :
>
>
>
>
>
> > I implemented this ->http://www.apl.jhu.edu/~hall/lisp/Hanoi.lispin
> > both flavors of Python: 2.6.2 and 3.0.1 (CPython)
>
> > The code:
> > #!/usr/bin/env python
> > def remaining_peg (peg1, peg2):
> >        return (6 - peg1 - peg2)
>
> > def hanoi (num_discs, start, end):
> >        if (1 == num_discs):
> >                print "Top of peg {0} to peg {1}".format(start,end) # used 
> > print()
> > for Py 3.0.1
>
> >        else:
> >                hanoi ((num_discs - 1), start, (remaining_peg (start, end)))
> >                hanoi (1, start, end)
> >                hanoi ((num_discs - 1), (remaining_peg (start, end)), end)
>
> > hanoi(20,2,3)
>
> > The times:            real          usr          sys
> > Python 2.6.2       7.994s    3.336s   3.296s
> > Python 3.0.1       55.302s  38.024s 5.876s
>
> > What happened to Python?
>
> I/O in Python 3.0 is known to be slow, because the bulk of the
> implementation is in Python (rather than C). Python 3.1 addresses
> this. Here are some tests of 2.6.1 vs 3.1rc2. The first tests have the
> print commented out, the second are with the print, redirected to the
> null device. The tests are on a pretty slow Windows XP SP2 laptop.
>
> >timer & \Apps\Python26\python.exe hanoi.py & timer
>
> Timer 1 on: 15:54:53
> Timer 1 off: 15:54:57  Elapsed: 0:00:03.88
>
> >timer & \Apps\Python31\python.exe hanoi.py & timer
>
> Timer 1 on: 15:57:05
> Timer 1 off: 15:57:09  Elapsed: 0:00:03.67
>
> >timer & (\Apps\Python26\python.exe hanoi.py >nul) & timer
>
> Timer 1 on: 15:57:44
> Timer 1 off: 15:58:14  Elapsed: 0:00:29.91
>
> >timer & (\Apps\Python31\python.exe hanoi.py >nul) & timer
>
> Timer 1 on: 15:58:38
> Timer 1 off: 15:59:09  Elapsed: 0:00:30.63
>
> Nothing much in it.
>
> Paul.

Thank you for clearing that up.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread Paul Rubin
[email protected] (Aahz) writes:
> (In particular, WRT the bisect module, although insertion and deletion
> are O(N), the constant factor for doing a simple memory move at C speed
> swamps bytecode until N gets very large -- and we already have
> collections.deque() for some other common use cases.)

Again, at least in my case, I'd hope for an immutable structure.

Also, "N very large" is likely to mean no more than a few thousand,
which is small by today's standards.  And the C speed difference goes
away completely if the tree implementation is also in C.

Hedgehog Lisp has a good functional AVL tree implementation written in
C, that I might try to wrap with the Python C API sometime.  I think
it is LGPL licensed though, not so good for the Python stdlib.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread Daniel Stutzbach
On Fri, Jun 26, 2009 at 1:54 AM, Miles Kaufmann  wrote:

> On Jun 26, 2009, at 2:23 AM, Chris Rebert wrote:
>
>> That's pretty much the bisect module in a nutshell. It manipulates a
>> sorted list using binary search.
>>
>
> With O(n) insertions and removals, though.  A decent self-balancing binary
> tree will generally do those in O(log n).


FWIW, you can get O(log**2 n) inserts and deletes by using the bisect module
on my blist extension type (http://pypi.python.org/pypi/blist/).  It's a
drop-in replacement for list(), with different asymptotic performance
characteristics.

Copying a blist is O(1), so the functional-programming types can wrap it in
non-mutating semantics if they so choose. ;)

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "The system cannot execute the specified program."

2009-06-26 Thread Trent Mick

Tim Slattery wrote:

Tim Slattery  wrote:


Our office has a copy of Python 3.0 installed on a network share
device. When I try to run it I get this message: "The system cannot
execute the specified program."


I should add that before I knew about our shared installation, I
downloaded the AS distribution of Python 2.6 from ActiveState. Their
install procedure is a *.bat file that calls Python to put everything
in the right place. When the bat file tries to invoke Python, I get
the same message.



I'm jumping in mid-thread here, so apologies if I've missed something. 
Just want to clarify something: the main AS distribution of Python 
(ActivePython) for Windows is an MSI.


There is sometimes a .zip file with an install.bat -- but that isn't 
really intended for wide use. Is that what you are referring to here?



Cheers,
Trent

--
Trent Mick
trentm at activestate.com
http://trentm.com/blog/
--
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread João Valverde

Aahz wrote:

In article <[email protected]>,
Steven D'Aprano   wrote:
  
Hash tables (dicts) are useful for many of the same things that trees are 
useful for, but they are different data structures with different 
strengths and weaknesses, and different uses. To argue that we don't need 
trees because we have dicts makes as much sense as arguing that we don't 
need dicts because we have lists.



The problem is that trees are like standards: there are so many to choose
from.  Each has its own tradeoffs, and because Python dicts and lists can
substitute for many of the traditionals uses of trees, the tradeoffs are
less clear.  I think nobody would object to adding trees to the standard
library, but it will certainly require a clear PEP, preferably with a
pointer to an existing PyPI library that has acquired real-world use.


  

Wish I had asked this before this year's GSoC started.

What's lacking is an associative array that preserves ordering, doesn't 
require a hash function and has fast insertions and deletions in 
O(log(n)). The particular algorithm to achieve this is a secondary 
issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault 
for having opened the topic with simply "trees" instead, it would have 
avoided this vagueness problem, but I'm genuinely surprised to know 
there are no data structures that efficiently support such a common need 
in Python. And I really enjoy the using this language.

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread norseman

Scott David Daniels wrote:

norseman wrote:
...  A note here:  In reading the original posting I get symbols that 
are not

familiar to me as alphabet.
 From the line in your original:
 Label(root, text='ęóąśłżźćń').pack()
I see text='
   then an e with a goatee
a  capitol O with an accent symbol on top (')
an a with a tail on the right
a  s with an accent on top
an I do no not know what - maybe some sort of l with a
   slash through the middle
a  couple of z with accents on top
a  capitol C with an accent on top
a  n with a short bar on top


Here's something to try in any future circumstances:

Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit 
(Intel)] on win32

Type "copyright", "credits" or "license()" for more information.
 >>> import unicodedata as ud
 >>> for ch in 'ęóąśłżźćń':
print('%3d %4x %c %s' % (ord(ch), ord(ch), ch, ud.name(ch)))


281  119 ę LATIN SMALL LETTER E WITH OGONEK
243   f3 ó LATIN SMALL LETTER O WITH ACUTE
261  105 ą LATIN SMALL LETTER A WITH OGONEK
347  15b ś LATIN SMALL LETTER S WITH ACUTE
322  142 ł LATIN SMALL LETTER L WITH STROKE
380  17c ż LATIN SMALL LETTER Z WITH DOT ABOVE
378  17a ź LATIN SMALL LETTER Z WITH ACUTE
263  107 ć LATIN SMALL LETTER C WITH ACUTE
324  144 ń LATIN SMALL LETTER N WITH ACUTE

--Scott David Daniels
[email protected]

==
Good thought, good idea, useful tool.

BUT - compare your output to what I *see*.
And I do not see any f3 anywhere except in the doc ref I copy/duped and 
in this file.


I suspect the mail handlers all have some differences.

I also suspect Window$ is still cooking it's outputs. It has a long 
history of saying one thing and doing another.


I used to program exclusively in assembly. I know for a fact Window$ can 
 and does lie.  Little ones, not often, but like your f3.  I don't have 
one. Not from the copy/paste of the original posting, not anywhere I 
have looked in reviewing possible cause/effect of the problem posted. I 
do have a C3 B3 byte pair after the 30 31 31 39  (0119) and before the 
5C (\) that follows the 0119.  MC shows it as a CAP-A with a tilde on 
top of it. Firefox shows it as a CAP-O with an accent on top. (Kids 
today call the Accent a single quote.)


I do not know what Window$ program to guide you to for proper hex 
listings.  I'm not even sure an accurate one exists. (No doubt someone 
will now list a few thousand of them. :)



Maybe zipping and transferring the .zip will help - maybe not.  I would 
like to know the results.




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


Re: os.system vs subprocess

2009-06-26 Thread Nate
I ended up going with this:

http://code.activestate.com/recipes/440554/

seems to feed me new lines of output atleast before the subprocess
finishes, with some adjustment of the time delays.  I'll guess I'll
just be packing winpy into the installer.  Or something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-26 Thread Stefan Behnel
João Valverde wrote:
> What's lacking is an associative array that preserves ordering, doesn't
> require a hash function and has fast insertions and deletions in
> O(log(n)).
> [...]
> I'm genuinely surprised to know
> there are no data structures that efficiently support such a common need
> in Python.

That's because it's simply not that a common need (in the sense that there
isn't a suitable alternative). I know that Trees have their use cases where
they really shine, but in surprisingly many cases a dict, a set, a list or
a combination of them will do just fine. And if you find a case where those
just don't fit, you may need a database anyway.

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


Re: No trees in the stdlib?

2009-06-26 Thread Aahz
In article ,
=?ISO-8859-1?Q?Jo=E3o_Valverde?=   wrote:
>
>What's lacking is an associative array that preserves ordering, doesn't 
>require a hash function and has fast insertions and deletions in 
>O(log(n)). The particular algorithm to achieve this is a secondary 
>issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault 
>for having opened the topic with simply "trees" instead, it would have 
>avoided this vagueness problem, but I'm genuinely surprised to know 
>there are no data structures that efficiently support such a common need 
>in Python. And I really enjoy the using this language.

Why AVL/RBT instead of B*?  It's not that simple  Another problem is
that unless the tree is coded in C, the constant factors are going to
swamp algorithmic complexity for many use cases -- that in turn makes it
more difficult to deploy a PyPI library for real-world testing.

Anyway, I'm *not* trying to discourage you, just explain some of the
roadblocks to acceptance that likely are why it hasn't already happened.

If you're serious about pushing this through, you have two options:

* Write the code and corresponding PEP yourself (which leads to the
second option, anyway)

* Lobby on the python-ideas mailing list
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


alternative to JoinableQueue's please

2009-06-26 Thread Filipe Fernandes
I'm currently using the multiprocessing package and I'm hugely
impressed at its simplicity (thanks very much Jesse Noller).

Although, it seems that there's a bug in JoinableQueue's which renders
using it pointless over a regular Queue as per Issue 4660

http://bugs.python.org/issue4660

To re-iterate... task_done() which is to be called for each get()
throws the exception:

ValueError: task_done() called too many times

every once in a while.  The reasons for this are outlined by Brian in
the issue above, but no confirmation has been provided.

The reasons for using JoinableQueue I think are obvious.  I want to
block the main processing using queue.join() until the tasks that have
been placed on the queue have been finished by the worker processes.

I can't be the only one experiencing this (besides Brian)... are there
others who ran into this?  Are there work arounds (besides a
home-brewed one) ?


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


Re: No trees in the stdlib?

2009-06-26 Thread Carl Banks
On Jun 26, 7:35 am, Hallvard B Furuseth 
wrote:
> Stefan Behnel writes:
> >João Valverde wrote:
> >> Besides some interface glitches, like returning None
> >> on delete if I recall correctly.
>
> > That's actually not /that/ uncommon. Operations that change an object are
> > not (side-effect free) functions, so it's just purity if they do not have a
> > return value.
>
> It's purity that they don't return the modified tree/dict/whatever.
> They can still return the deleted element and remain pure.

Correct, dict.pop does exactly this.


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


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Robert Kern

On 2009-06-26 02:17, Ulrich Eckhardt wrote:

Robert Kern wrote:

I wish people would stop representing decimal floating point arithmetic as
"more accurate" than binary floating point arithmetic.


Those that failed, learned. You only see those that haven't learnt yet.

Dialog between two teachers:
T1: Oh those pupils, I told them hundred times! when will they learn?
T2: They did, but there's always new pupils.


Unfortunately, I keep seeing people who claim to be old hands at floating point 
making these unlearned remarks. I have no issue with neophytes like the OP 
expecting different results and asking questions. It is those who answer them 
with an air of authority that need to take a greater responsibility for knowing 
what they are talking about. I lament the teachers, not the pupils.


--
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


change the first character of the line to uppercase in a text file

2009-06-26 Thread powah
How to change the first character of the line to uppercase in a text
file?
e.g.
input is:
abc xyz
Bd ef
gH ij

output should be:
Abc xyz
Bd ef
GH ij
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-26 Thread Kee Nethery
First, thanks to everyone who responded. Figured I'd test all the  
suggestions and provide a response to the list. Here goes ...


On Jun 25, 2009, at 7:38 PM, Nobody wrote:

Why do you need an ElementTree rather than an Element? XML(string)  
returns
the root element, as if you had used et.parse(f).getroot(). You can  
turn

this into an ElementTree with e.g. et.ElementTree(XML(string)).


I tried this:
   et.ElementTree(XML(theXmlData))
and it did not work.

I had to modify it to this to get it to work:
   et.ElementTree(et.XML(theXmlData))



formPostData = cgi.FieldStorage()
theXmlData = formPostData['theXml'].value
theXmlDataTree =
et 
.parse 
(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData))


If you want to treat a string as a file, use StringIO.


I tried this:
   import StringIO
   theXmlDataTree = et.parse(StringIO.StringIO(theXmlData))
   orderXml = theXmlDataTree.findall('purchase')

and it did work. StringIO converts the string into what looks like a  
file so parse can process it as a file. Cool.


On Jun 25, 2009, at 7:47 PM, unayok wrote:


I'm not sure what you're expecting.  It looks to me like things are
working okay:

My test script:

[snip]


I agree your code works.

When I tried:
   theXmlDataTree = et.fromstring(theXmlData)
   orderXml = theXmlDataTree.findall('purchase')

When I modified mine to programmatically look inside using the "for  
element in theXmlDataTree" I was able to see the contents. The  
debugger I am using does not offer me a window into the ElementTree  
data and that was part of the problem. So yes, et.fromstring is  
working correctly. It helps to have someone show me the missing step  
needed to confirm the code works and the IDE does not.




On Jun 25, 2009, at 8:04 PM, Carl Banks wrote:

I believe you are misunderstanding something.  et.XML and
et.fromstring return Elements, whereas et.parse returns an
ElementTree.  These are two different things; however, both of them
"contain all the XML".  In fact, an ElementTree (which is returned by
et.parse) is just a container for the root Element (returned by
et.fromstring)--and it adds no important functionality to the root
Element as far as I can tell.


Thank you for explaining the difference. I absolutely was  
misunderstanding this.



Given an Element (as returned by et.XML or et.fromstring) you can pass
it to the ElementTree constructor to get an ElementTree instance.  The
following line should give you something you can "play with":

theXmlDataTree = et.ElementTree(et.fromstring(theXmlData))


Yes this works.



On Jun 25, 2009, at 11:39 PM, Stefan Behnel wrote:


If you want to parse a document from a file or file-like object, use
parse(). Three use cases, three functions. The fourth use case of  
parsing a

document from a string does not have its own function, because it is
trivial to write

tree = parse(BytesIO(some_byte_string))


:-) Trivial for someone familiar with the language. For a newbie like  
me, that step was non-obvious.


If what you meant is actually parsing from a byte string, this is  
easily

done using BytesIO(), or StringIO() in Py2.x (x<6).


Yes, thanks! Looks like BytesIO is a v.3.x enhancement. Looks like the  
StringIO does what I need since all I'm doing is pulling the unicode  
string into et.parse. Am guessing that either would work equally well.




theXmlDataTree =
et 
.parse 
(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData))


This will not work because ET cannot parse from unicode strings  
(unless
they only contain plain ASCII characters and you happen to be using  
Python
2.x). lxml can parse from unicode strings, but it requires that the  
XML

must not have an encoding declaration (which would render it non
well-formed). This is convenient for parsing HTML, it's less  
convenient for

XML usually.


Right for my example, if the data is coming in as UTF-8 I believe I  
can do:
   theXmlDataTree = et.parse(StringIO.StringIO(theXmlData), encoding  
='utf-8')



Again, as a newbie, thanks to everyone who took the time to respond.  
Very helpful.

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


Re: "The system cannot execute the specified program."

2009-06-26 Thread Tim Slattery
Trent Mick  wrote:

>Tim Slattery wrote:
>> Tim Slattery  wrote:
>> 
>>> Our office has a copy of Python 3.0 installed on a network share
>>> device. When I try to run it I get this message: "The system cannot
>>> execute the specified program."
>> 
>> I should add that before I knew about our shared installation, I
>> downloaded the AS distribution of Python 2.6 from ActiveState. Their
>> install procedure is a *.bat file that calls Python to put everything
>> in the right place. When the bat file tries to invoke Python, I get
>> the same message.
>> 
>
>I'm jumping in mid-thread here, so apologies if I've missed something. 
>Just want to clarify something: the main AS distribution of Python 
>(ActivePython) for Windows is an MSI.

Given the way my machine here is locked down, I'm pretty sure I
couldn't run the *.msi file.

>There is sometimes a .zip file with an install.bat -- but that isn't 
>really intended for wide use. Is that what you are referring to here?

That's what it is. They give you a choice of MSI or AS. The AS choice
is a zip file that you unzip, then run the bat file on the top level.
There's no indication that it's "not intended for wide use".

-- 
Tim Slattery
[email protected]
http://members.cox.net/slatteryt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "The system cannot execute the specified program."

2009-06-26 Thread Tim Slattery
Duncan Booth  wrote:

>Tim Slattery  wrote:
>
>> Our office has a copy of Python 3.0 installed on a network share
>> device. When I try to run it I get this message: "The system cannot
>> execute the specified program."
>> 
>> When I googled that message, the links that came up had to do with
>> missing DLLs. So I fired up Dependency Walker and found out that there
>> were indeed DLLs that it needed that the OS couldn't find. So I
>> supplied those DLLs. And it still gives the same message, even though
>> Dependency Walker is now happy.
>> 
>> Does anybody have a clue what might cause this amazingly uninformative
>> message?
>
>Are you using Vista? 

No Vista involved. My machine is XP Pro. The server is some MS server
OS, I'm not sure which one.

>Alternatively for a non-Vista wild guess, could it be that Python 3.0 is 
>loading some libraries that use .Net and is therefore triggering the 'code 
>access security' which prevents the running of .Net applications from a 
>network share?

I saw nothing that remotely resembled that message.

-- 
Tim Slattery
[email protected]
http://members.cox.net/slatteryt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "The system cannot execute the specified program."

2009-06-26 Thread Trent Mick

Tim Slattery wrote:

That's what it is. They give you a choice of MSI or AS. The AS choice
is a zip file that you unzip, then run the bat file on the top level.
There's no indication that it's "not intended for wide use".


Granted not much, other than it isn't listed in the main download tables:
  http://www.activestate.com/activepython/downloads/
and not discussed in the install notes:
  http://docs.activestate.com/activepython/2.6/installnotes.html

Cheers,
Trent

--
Trent Mick
trentm at activestate.com
http://trentm.com/blog/
--
http://mail.python.org/mailman/listinfo/python-list


Re: change the first character of the line to uppercase in a text file

2009-06-26 Thread Emile van Sebille

On 6/26/2009 12:43 PM powah said...

How to change the first character of the line to uppercase in a text
file?
e.g.
input is:
abc xyz
Bd ef
gH ij

output should be:
Abc xyz
Bd ef
GH ij


How far have you gotten?

Emile

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


Re: "The system cannot execute the specified program."

2009-06-26 Thread Terry Reedy

Tim Slattery wrote:

Tim Slattery  wrote:


Our office has a copy of Python 3.0 installed on a network share
device. When I try to run it I get this message: "The system cannot
execute the specified program."


Slightly OT, but do try to replace that with 3.1 as soon as you can.
Significant improvements in certain areas.

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


Re: change the first character of the line to uppercase in a text file

2009-06-26 Thread Chris Rebert
On Fri, Jun 26, 2009 at 12:43 PM, powah wrote:
> How to change the first character of the line to uppercase in a text
> file?
> e.g.
> input is:
> abc xyz
> Bd ef
> gH ij
>
> output should be:
> Abc xyz
> Bd ef
> GH ij

We're not in the business of doing homework. Some hints though:

`s.upper()` converts the string in variable `s` to all upper case
(e.g. "aBcD".upper() --> "ABCD")
`for line in afile:` iterates over each line in a file object. `afile`
is the file object and `line` gets assigned each line in turn.
`s[x]` gets you the (x+1)-th character in the string `s` (e.g.
"abcd"[2] --> "c")

And here are the docs on working with files:
http://docs.python.org/library/functions.html#open
http://docs.python.org/library/stdtypes.html#file-objects

That should be enough to get you started.

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


Re: change the first character of the line to uppercase in a text file

2009-06-26 Thread Tim Chase

powah wrote:

How to change the first character of the line to uppercase in a text
file?
e.g.
input is:
abc xyz
Bd ef
gH ij

output should be:
Abc xyz
Bd ef
GH ij


While you're asking the Python list, I'd just use GNU sed:

  sed -i 's/./\U&/' myfile.txt

I don't know if the "\U"=="make the replacement uppercase" is a 
GNU-sed specific thing, but it works here on my Debian box's 
version 4.1.5 when I tested it.


-tkc




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


Re: change the first character of the line to uppercase in a text file

2009-06-26 Thread Scott David Daniels

powah wrote:

How to change the first character of the line to uppercase in a text
file?

Here is an English hint on the above:
The "How ... file" above is a noun phrase, and is not a sentence,
never mind a question.  Putting a question mark after the noun phrase
does not make that phrase a question.  "Would someone explain to me how 
...file?" would be a question albeit inappropriate here, since you

showed no work.

By the way, that strange sentence structure usually clues me in that
it is you again, apparently someone who does homework by posting to
the list before attempting to work it out alone.

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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Scott David Daniels

norseman wrote:

Scott David Daniels wrote:

norseman wrote:

...  A note here:  In reading the original posting I get ...
   then an e with a goatee


Here's something to try in any future circumstances:
  

Good thought, good idea, useful tool.

BUT - compare your output to what I *see*.

Have you considered font issues when printing?
The best encoding will not show anything reasonable when printed with a
font without the characters in question.  I'm not saying I know its
wrong, only that there is another issue to check.
you might both swap outputs from the over-explict printing I used above.

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


Re: alternative to JoinableQueue's please

2009-06-26 Thread Raymond Hettinger
[Filipe Fernandes]
> The reasons for using JoinableQueue I think are obvious.  I want to
> block the main processing using queue.join() until the tasks that have
> been placed on the queue have been finished by the worker processes.
>
> I can't be the only one experiencing this (besides Brian)... are there
> others who ran into this?  Are there work arounds (besides a
> home-brewed one) ?

Before Queue.task_done() and Queue.task_join() were added, other
idioms were used.

One technique is to use a second queue to track incomplete tasks.

# adding work
unfinished_tasks.put(None)
q.put(task)


# doing work
t = q.get()
f(t)
unfinished_tasks.get()


# waiting for unfinished tasks to complete
while unfinished_tasks.qsize():
sleep(0.1)



Raymond

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


Re: Python simple web development

2009-06-26 Thread Charles Yeomans

Or you could try my approach and write your own web app.

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


Re: Python simple web development

2009-06-26 Thread Daniel Fetchinson
>> What I've read about Django, Turbogears is that they are powerful
>> enough to create big web-based portals, applications, etc.
>> I need just simple forms without any sophisticated functionality.
>> So again: why I am wrong ?
>
> Just because something is powerful doesn't mean you can't do simple
> things with it.

But complexity typically brings in an extra overhead that the OP might
not need. I'm using turbogears for a project but for other simple
things I don't, because the all the super powerful infrastructure of
turbogears is just not necessary and slows things down without a
reason.

So I would recommend the OP against using either django or turbogears
if the project is really small and will stay small in the future. This
last point is hard to guess in advance though :)

Cheers,
Daniel

> Have a read of the first few chapters of the Django book...
>
> http://www.djangobook.com/



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python simple web development

2009-06-26 Thread Thomas Allen
On Jun 25, 3:29 am, Private Private  wrote:
> Hi,
>
> I am looking for a python library which will allow me to do a simple
> web development. I need to use
> some forms (but nice looking :-) ), creating images based on input
> from those forms, etc. I have read a bit about Django and TurboGears
> but I am afraid that this is too big for my requirements (am I
> wrong ?).
>
> Can you suggest anything ?

I don't think anything's lighter than web.py.

http://webpy.org/

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


Re: Dynamic method invocation

2009-06-26 Thread jythonuser
Sorry for being a little vague.  The last part of your response seems
like what I would need.  So here are more details on what I am trying
to do.

I have an extensible command shell in java where commmand providers
plug in to supply new commands.  I have a java class called MyShell
which has execCommand method on it.  Thus MyShell class does not have
a concrete method on it for each command that it supports (e.g. grep,
ls, cat etc) but a generic execCommand method that takes the name of
the command and command params as arguments.

clas MyShell () {
Object execCommand (cmdName, params) {
Object o = // find command object from command name
return o.invoke (cmdName, params);
}
|

Now I want to use this in jython.  So I could do something like
shell = MyShell()
shell.exec ("grep", grep_args)

What I would like to do is -
shell.grep (grep_args)

That way my users don't have to use some gorpy exec/invoke syntax for
each command but think that shell has all the commands defined on it.
So based on your example I am hoping that I can use getattr on "some"
object that returns me "some" method that I can call.

Does this make sense and is there a way to do this in jython?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic method invocation

2009-06-26 Thread jythonuser
Actually let me add that in jython I don't need to always use
MyShell.  It may be ok to wrapper it with some Jython class which then
delegates to MyShell. So something like

shell = MyJythonShell()
shell.grep (grep_args)

So MyJythonShell is defined in Jython which calls MyShell.

Am wondering how to go about all this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2*2 is 9.6 ... or maybe it isn't?

2009-06-26 Thread Michael Torrie
Robert Kern wrote:
> In the former case, you can claim that decimal floating point is more 
> accurate 
> *for those problems*. But as soon as you have a division operation, decimal 
> floating point has the same accuracy problems as binary floating point.

True.  Poor choice of words on my part.  No matter what representation
one chooses for numbers, we can remember that digits != precision.
That's why significant digits were drilled into our heads in physics!
That's the reason IEEE actually works out for most things that we need
floating point for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python simple web development

2009-06-26 Thread Petr Messner
What about Werkzeug? I like its simplicity (well, basically everything
I need are WSGI request/response objects :) + some templating
library).

Petr


2009/6/25 Private Private :
> Hi,
>
> I am looking for a python library which will allow me to do a simple
> web development. I need to use
> some forms (but nice looking :-) ), creating images based on input
> from those forms, etc. I have read a bit about Django and TurboGears
> but I am afraid that this is too big for my requirements (am I
> wrong ?).
>
> Can you suggest anything ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Martin v. Löwis
> And I do not see any f3 anywhere except in the doc ref I copy/duped and
> in this file.

That surely is a bug in your email program - get a better one.

Take a look at

http://mail.python.org/pipermail/python-list/2009-June/717666.html

which displays correctly - maybe you can find a web browser that works.

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


Re: No trees in the stdlib?

2009-06-26 Thread Raymond Hettinger
[Tom Reed]
> Why no trees in the standard library, if not as a built in?

The sqlite3 module is built on a binary-tree structure.
It can be used with persistent data or kept in-memory.
The gdbm module has similar flexibility (see the F mode).
FWIW, there are some ASPN implementing various types of
trees (red-black, pairing heaps, etc).


Raymond

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


Re: No trees in the stdlib?

2009-06-26 Thread Raymond Hettinger
[João Valverde]
> What's lacking is an associative array that preserves ordering, doesn't
> require a hash function and has fast insertions and deletions in
> O(log(n)).

FWIW, Py3.1 has an OrderedDict() that preserves insertion order.
It has O(1) lookup, deletion, insertion, and popping; and O(n)
iteration.  The ASPN Cookbook has equivalent code that runs on
earlier versions of Python.


> in Python. And I really enjoy the using this language.

Am glad you like it.


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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Piet van Oostrum
> Sebastian Pająk  (SP) wrote:

>SP> Maybe this picture will tell you more:
>SP> http://files.getdropbox.com/u/1211593/tkinter.png

>SP> The original script:
>SP> http://files.getdropbox.com/u/1211593/test1.py

>SP> May someone can confirm this osx behaviour?

Yes, I get the same. But it is a problem of the underlying Tk
implementation. I get the same strange behaviour in wish.

Text widgets seem to have the same problem and it has to do with the use
of QuickDraw rather than ATSUI in Tcl/Tk 8.4. Whereas 8.5 uses ATSUI but
this seems to cause other problems.

See:
http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862062
http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862807

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MultiValueDict?

2009-06-26 Thread John Machin
On Jun 27, 2:09 am, BarakatX2  wrote:
>  png)>, ,
> ]}>

There is nothing in this schema to suggest that any object has a .name
attribute .

>
>     for f in files['rqFiles']:
>         print f.name
>
> This gives me an "'str' object has no attribute 'name'" error. I don't
> know if there is a special way to access MultiValueDicts values, but I
> assumed each key has a list that is accessed just like any other list.

You might start by telling us what a MultiValueDict is -- it's not
from the standard Python distribution AFAICT. Consider asking the
source of MultiValueDicts. Consider reading any docs for the module or
package that defines MultiValueDicts. Consider inspecting some of the
objects:

print files['rqFiles']
# given your error message, probably get sth like ['foo.png',
'bar.png', ...]
print files




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


Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Sebastian Pająk
2009/6/27 Piet van Oostrum :
>> Sebastian Pająk  (SP) wrote:
>
>>SP> Maybe this picture will tell you more:
>>SP> http://files.getdropbox.com/u/1211593/tkinter.png
>
>>SP> The original script:
>>SP> http://files.getdropbox.com/u/1211593/test1.py
>
>>SP> May someone can confirm this osx behaviour?
>
> Yes, I get the same. But it is a problem of the underlying Tk
> implementation. I get the same strange behaviour in wish.
>
> Text widgets seem to have the same problem and it has to do with the use
> of QuickDraw rather than ATSUI in Tcl/Tk 8.4. Whereas 8.5 uses ATSUI but
> this seems to cause other problems.
>

Uhhh. good to know
It should be written somewhere with BIG letters so people like me
whouldn't be confused...

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


Replacing a built-in method of a module object instance

2009-06-26 Thread David Hirschfield
I have a need to replace one of the built-in methods of an arbitrary 
instance of a module in some python code I'm writing.


Specifically, I want to replace the __getattribute__() method of the 
module I'm handed with my own __getattribute__() method which will do 
some special work on the attribute before letting the normal attribute 
lookup continue.


I'm not sure how this would be done. I've looked at all the 
documentation on customizing classes and creating instance methods...but 
I think I'm missing something about how built-in methods are defined for 
built-in types, and where I'd have to replace it. I tried this naive 
approach, which doesn't work:


m = 

def __getattribute__(self, attr):
   print "modified getattribute:",attr
   return object.__getattribute__(self, attr)

import types
m.__getattribute__ = types.MethodType(__getattribute__,m)

It seems to create an appropriately named method on the module instance, 
but that method isn't called when doing any attribute lookups, so 
something's not right.

Any ideas? Is this even possible?
Thanks in advance!
-David

--
Presenting:
mediocre nebula.


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


looking for a book on python

2009-06-26 Thread Randy Foiles

Hello and thank you for taking your time to read this.
	I was interested in learning about python.  In the long ago past I did 
learn some programing but I have not used any of it for years.  I do 
remember some basics however so the book does not have to be for a total 
beginner.  (C, C++, BASIC, Visual BASIC, Pascal and some ADA)
	I have been using Linux for a while and overall still don't know much 
about it but I can find my way.  I have my system dual boot with windows 
vista.
	I do realize that everyone is different but I would like to see some 
suggestions and maybe reasons why you think it is good.  I have looked 
for/searched and found a few different books but as my means are a bit 
limited right now I don't really want to buy several just one or maybe 
two books.
	Oh and if someone knows a place to find some used books of this sort 
that would be great (ebay I guess :)

Thanks for your thoughts
Randy theslayers9   gmail
--
http://mail.python.org/mailman/listinfo/python-list


Re: alternative to JoinableQueue's please

2009-06-26 Thread Filipe Fernandes

Raymond Hettinger wrote:
> [Filipe Fernandes]
>> The reasons for using JoinableQueue I think are obvious.  I want to
>> block the main processing using queue.join() until the tasks that have
>> been placed on the queue have been finished by the worker processes.
>>
>> I can't be the only one experiencing this (besides Brian)... are there
>> others who ran into this?  Are there work arounds (besides a
>> home-brewed one) ?
>
> Before Queue.task_done() and Queue.task_join() were added, other
> idioms were used.
>
> One technique is to use a second queue to track incomplete tasks.
>
> # adding work
> unfinished_tasks.put(None)
> q.put(task)
>
>
> # doing work
> t = q.get()
> f(t)
> unfinished_tasks.get()
>
>
> # waiting for unfinished tasks to complete
> while unfinished_tasks.qsize():
> sleep(0.1)

Thanks Raymond... yours is by far is the simplest and should have been an 
obvious solution.  I didn't want to stray too far from what I had and this 
fits the bill.


In case others are curious...

I had looked at using the example in
http://docs.python.org/library/multiprocessing.html#using-a-remote-manager

to use the traditional Queue from module Queue which includes the join and 
task_done method calls. But creating a server process/thread just for that 
is rather over-kill.


I also looked at using process pools asynchronously and waiting for the 
iterators to come back to determine if jobs were completed.


But your solution is  the simplest to implement.  And easy 
enough to create a composite class containing the two queues to simulate 
the real one (although I have not tried the following, I'm not in the 
office right now).



class JoinableQueue(object):
def __init__(*args, **kwargs):
self.__tasks = Queue()
self.__queue = Queue(*args, **kwargs)

def put(self, *args, **kwargs):
self.__tasks.put(None)
self.__queue.put(*args, **kwargs)

def get(self, *args, **kwargs):
return self.__queue.get(*args, **kwargs)

def task_done():
try:
   self.__tasks.get(False)
except Queue.Empty:
   raise ValueError('task_done called too many times')

def join():
while not self.__tasks.empty():
sleep(0.1)

[Add methods to simulate as required]

filipe

ps: Thanks Raymond for the quick reply... and I feel rather apologetic for 
having bothered the list with this :S


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


Re: looking for a book on python

2009-06-26 Thread Horace Blegg
Hello,

http://diveintopython.org/ - might be a good place to start.

There are also a bunch of free programming books (some related to python,
some not) to be found here:
http://www.e-booksdirectory.com/programming.php#python - How good these
books may or may not be is up to you to find out. Also, some uni's/collegs
have taken to posting videos of classes online, that you can watch for free.
An example would be: http://webcast.berkeley.edu/ - Go to courses, and then
'select semester' (upper right) and start looking through. Some years have
more programming classes than others. Not explicitly python, but programming
is programming is programming or something like that.

Should be enough to get you started :)


On Fri, Jun 26, 2009 at 5:48 PM, Randy Foiles  wrote:

> Hello and thank you for taking your time to read this.
>I was interested in learning about python.  In the long ago past I
> did learn some programing but I have not used any of it for years.  I do
> remember some basics however so the book does not have to be for a total
> beginner.  (C, C++, BASIC, Visual BASIC, Pascal and some ADA)
>I have been using Linux for a while and overall still don't know
> much about it but I can find my way.  I have my system dual boot with
> windows vista.
>I do realize that everyone is different but I would like to see some
> suggestions and maybe reasons why you think it is good.  I have looked
> for/searched and found a few different books but as my means are a bit
> limited right now I don't really want to buy several just one or maybe two
> books.
>Oh and if someone knows a place to find some used books of this sort
> that would be great (ebay I guess :)
> Thanks for your thoughts
> Randy theslayers9   gmail
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >