Re: Extract all words that begin with x

2010-05-12 Thread Bryan
Terry Reedy wrote:
> Thank you for that timing report.

Enjoyed doing it, and more on that below.

> My main point is that there are two ways to fetch a char, the difference
> being the error return -- exception IndexError versus error value ''.
> This is an example of out-of-band versus in-band error/exception
> signaling, which programmers, especially of Python, should understand.

Sure. I think your posts and the bits of Python code they contain are
great. Slicing is amazingly useful, and it helps that slices don't
barf just because 'start' or 'stop' falls outside the index range.

My main point was to show off how Python and its standard library make
answering the which-is-faster question easy. I think that's another
thing Python programmers should understand, even though I just learned
how today.

Now back to the arguably-interesting issue of speed in the particular
problem here: 'Superpollo' had suggested another variant, which I
appended to my timeit targets, resulting in:

[s for s in strs if s.startswith('a')]  took:  5.68393977159
[s for s in strs if s[:1] == 'a']  took:  3.31676491502
[s for s in strs if s and s[0] == 'a']  took:  2.29392950076

Superpollo's condition -- s and s[0] == 'a' -- is the fastest of the
three.

What's more, in my timeit script the strings in the list are all of
length 5, so the 'and' never gets to short-circuit. If a major portion
of the strings are in fact empty superpollo's condition should do even
better. But I didn't test and time that. Yet.

-Bryan Olson


# - timeit code -

from random import choice
from string import ascii_lowercase as letters
from timeit import Timer

strs = [''.join([choice(letters) for _ in range(5)])
for _ in range(5000)]

way1 = "[s for s in strs if s.startswith('a')]"
way2 = "[s for s in strs if s[:1] == 'a']"
way3 = "[s for s in strs if s and s[0] == 'a']"

assert eval(way1) == eval(way2) == eval(way3)

for way in [way1, way2, way3]:
t = Timer(way, 'from __main__ import strs')
print(way, ' took: ', t.timeit(1000))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating over dict and removing some elements

2010-05-12 Thread Bryan
Terry Reedy wrote:
[...]
> for k in [k for k in d if d[k] == 'two']:
>          d.pop(k)

We have a winner.


--
--Bryan


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


Re: Iterating over dict and removing some elements

2010-05-12 Thread Rebelo

On 05/11/2010 05:08 PM, Ulrich Eckhardt wrote:

Hi!

I wrote a simple loop like this:

   d = {}
   ...
   for k in d:
   if some_condition(d[k]):
   d.pop(k)

If I run this, Python complains that the dictionary size changed during
iteration. I understand that the iterator relies on the internal structure
not changing, but how would I structure this loop otherwise?

My first approach was to simply postpone removing the elements, but I was
wondering if there was a more elegant solution.

Thanks!

Uli




i am wondering why not like this:

>>> d = {1: 'one', 2: 'two', 3: 'three'}
>>> for k,v in d.items():
... if k==1:
...  del d[k]
...
>>> d
{2: 'two', 3: 'three'}
>>>

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


Re.: reading xml from python - Sum-up

2010-05-12 Thread Hvidberg, Martin
Thanks to all - Just to give a positive feed back.
The following solution works for me:


from xml.etree.ElementTree import ElementTree

tree = ElementTree()

tree.parse('inifile.xml')

dicIni = dict((child.tag, child.text) for child in tree.getroot().getchildren())

:-) Martin



This email is made of 100% recycled bytes ...



From: Hvidberg, Martin
Sent: Tuesday, May 11, 2010 2:54 PM
To: '[email protected]'
Subject: reading xml from python

I'm looking for at way to read (and later write) small simple .xml file from 
Python.

e.g. I would like to read the following from a small ini.xml file into a 
dictionary.



 default
 False
 False
 UBMlight
 True

I would prefer a relative simple (not too much creating new classes) way to do 
this.

Any suggestions appreciated.

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


Re: Upgrade Python 2.6.4 to 2.6.5

2010-05-12 Thread Werner F. Bruhin

On 11/05/2010 23:13, Martin v. Loewis wrote:

When will it install into system32?
 

When you install "for all users".

   

Did the upgrade inform you that it was an upgrade, or did it warn you
that you would overwrite the previous installation?

   

It warned me that there is a previous installation.
 

Hmm. You don't remember the exact message, do you?
I guess it was a popup saying "[TARGETDIR] exists. Are you sure you want
to overwrite existing files?", and that it was not
a red text saying "This update will replace your existing [ProductLine]
installation."

Please confirm.
   

Correct that was it.

If so, you now have two Python installations in the same location; one
for all users, and the older one just for you (or vice versa).
   

Yes, that is what I did ages ago.

I recommend to uninstall them both, and start over.
   

O.K., will do that.

Thanks for your help
Werner

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


Re: Picking a license

2010-05-12 Thread Lie Ryan
On 05/12/10 06:50, Patrick Maupin wrote:
> On May 11, 5:34 am, Paul Boddie  wrote:
>> On 10 Mai, 20:36, Patrick Maupin  wrote:
>>>  The fact is, I know the man would force me to pay for the chocolate, so in
>>> some cases that enters into the equation and keeps me from wanting the
>>> chocolate.
>>
>> If the man said, "please take the chocolate, but I want you to share
>> it with your friends", and you refused to do so because you couldn't
>> accept that condition, would it be right to say, "that man is forcing
>> me to share chocolate with my friends"?
> 
> But the thing is, he's *not* making me share the chocolate with any of
> my friends.  He's not even making me share my special peanut butter
> and chocolate.  What he's making me do is, if I give my peanut butter
> and chocolate to one of my friends, he's making me make *that* friend
> promise to share.  I try not to impose obligations like that on my
> friends, so obviously the "nice" man with the chocolate isn't my
> friend!

The analogy breaks here; unlike chocolate, the value of software/source
code, if shared, doesn't decrease (in fact, many software increases its
value when shared liberally, e.g. p2p apps).

There might be certain cases where the software contains some trade
secret whose value decreases the more people knows about it; but sharing
does not decrease the value of the software, at least not directly, it
is the value of the secret that decreases because of the sharing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 80, Issue 108

2010-05-12 Thread varahalu 2400
please dont send mails





From: "[email protected]" 
To: [email protected]
Sent: Wed, 12 May, 2010 12:00:02 AM
Subject: Python-list Digest, Vol 80, Issue 108

Note: Forwarded message is attached.

Send Python-list mailing list submissions to
[email protected]

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
[email protected]

You can reach the person managing the list at
[email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."
Today's Topics:

   1. Re: HTTP Post Request (Kushal Kumaran)
   2. Re: Picking a license (Lie Ryan)
   3. Re: Upgrade Python 2.6.4 to 2.6.5 (Martin v. L?wis)
   4. Why the inconsistent of those two base64 methods? (Leo Jay)
   5. Re: Fastest way to calculate leading whitespace (dasacc22)
   6. PEP 3119 ABC - And how I learned to love the Abstract Bomb
  (Hatem Nassrat)
   7. Re: Extract all words that begin with x (Aahz)
   8. Re: PEP 3119 ABC - And how I learned to love the Abstract
  Bomb (Gabriel Genellina)
   9. Re: First Timer (Mensanator)
  10. Re: Extract all words that begin with x (Bryan)
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Re: accessing superclass methods from subclass

2010-05-12 Thread Bruno Desthuilliers

Chris Rebert a écrit :
(snip)

Here is how I would rewrite your example:

class Shape(object):
def __init__(self, x=0, y=0):
self.x = x
self.y = y

@property
def location(self):
return (self.x, self.y)

@location.setter
def location(self, val):
   self.x, self.y = val


Not necessary but helps documenting the expected interface:

  def draw(self):
  raise NotImplementedError("Abstract method")


class Square(Shape):
   def __init__(self,size):
   super(Square, self).__init__()
   self.size = size


Why can't I specify a Square location ??? This looks rather inconsistant 
and inconveniant to me...


def __init__(self, x=0, y=0, size=0):
super(Square, self).__init__(x, y)
self.size = size



   def draw(self):
   x, y = self.location
   # code to draw shape from location[0],location[1] at size size
   # etc...


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


Re: Iterating over dict and removing some elements

2010-05-12 Thread Bryan
Rebelo wrote:
> i am wondering why not like this:
>
>  >>> d = {1: 'one', 2: 'two', 3: 'three'}
>  >>> for k,v in d.items():
> ...     if k==1:
> ...          del d[k]
> ...
>  >>> d
> {2: 'two', 3: 'three'}
>  >>>

Mostly because there's no reason to get 'v' if you're not going to use
it. That may be just because you simplified the example, and if you
are working in Python 2.x and the real test for whether to delete
involves the value and not just the key, that's a reasonable solution.

On subtler issues, it constucts an unnecessarily long temporary list
in current Python 2.X, and fails in Python 3.x, as Terry Ready
explained.


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


Re: HTTP Post Request

2010-05-12 Thread [email protected]
On May 12, 6:13 am, Kushal Kumaran 
wrote:
> On Tue, May 11, 2010 at 3:59 PM, [email protected]  wrote:
> > On May 11, 10:56 am, "[email protected]"  wrote:
> >> On May 11, 5:06 am, Kushal Kumaran 
> >> wrote:
>
> >> > On Mon, May 10, 2010 at 8:26 PM, [email protected]  
> >> > wrote:
> >> > > On May 10, 10:22 am, Kushal Kumaran 
> >> > > wrote:
> >> > >> On Mon, May 10, 2010 at 7:30 PM, [email protected]  
> >> > >> wrote:
> >> > >> > Hi to all, i want to ask you a question, concerning the best way to 
> >> > >> > do
> >> > >> > the following as a POST request:
> >> > >> > There is server-servlet that accepts xml commands
> >> > >> > It had the following HTTP request headers:
>
> >> > >> >            Host: somehost.com
> >> > >> >            User-Agent: Jakarta Commons-HttpClient
> >> > >> >            Content-Type: text/xml
> >> > >> >            Content-Length: 415
>
> >> > >> > and the following request body (reformatted here for clarity):
>
> >> > >> >            
> >> > >> >            
> >> > >> >              search
> >> > >> >            
> >> > >> > How can i send the above to the Listener Servlet?
> >> > >> > Thanks in advance
>
> >> > >> Use the xmlrpclib module.
>
> >> > > OK, sending headers with xmlrpclib,
> >> > > but how do i send the XML message?
>
> >> > Your XML message is an XML RPC message.  You will use xmlrpclib like 
> >> > this:
>
> >> > server_proxy = xmlrpclib.ServerProxy(('somehost.com', 80))
> >> > result = server_proxy.search()
>
> >> > The call to server_proxy.search will result in an actual XML RPC
> >> > message being sent.
>
> >> > Read up on the xmlrpclib documentation 
> >> > here:http://docs.python.org/library/xmlrpclib.html, and the XMLRPC spec
> >> > here:http://www.xmlrpc.com/spec
>
> >> Ok I got it!
> >> Thank you!!!
>
> >> A.K
>
> > Apparently the server i'm trying to connect accepts only POST
> > connections. So xmlrpclib is useless.
> > I think I need the httplib library module.
>
> > Any hints?
>
> I don't understand.  xmlrpclib sends POST requests only.  Are you
> getting an exception?  If so, please post the entire stack trace.
>
> If you want to send the data "by hand", use the httplib module.  you
> can pass your XML to the HTTPConnection.request method as the "body"
> argument.
>
> --
> regards,
> kushal

Ok i found it. I sent the xml by hand with httplib module.
i use the last example of http://docs.python.org/library/httplib.html
and it worked.
Thank you very much for your response.

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


encoding issue (cp720)

2010-05-12 Thread M. Bashir Al-Noimi

Hi All,

I'm still a newbie in Python (I started learn it yesterday)  and I faced 
a huge problem cuz python always crashes because of encoding issue!



Fatal Python error: Py_Initialize: can't initialize sys standard streams
LookupError: unknown encoding: cp720
   


so I filed a bug report 
 
about it but I couldn't find a solution for this problem so could you 
please help me to run python correctly?


*Note:*

   * I'm using: Windows XP SP3 32Bit, Python 3.1.2
   * I tried to copy cp720.py
 
 to Python31\Lib\encodings but it didn't fix the issue and gives me
 an error message (see attachment plz)

--
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net

Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
  File "C:\Python31\lib\encodings\__init__.py", line 98, in search_function
level=0)
  File "C:\Python31\lib\encodings\cp720.py", line 50
u'\x00' #  0x00 -> CONTROL CHARACTER
  ^
SyntaxError: invalid syntax

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-12 Thread Alia Khouri
Paul Rubin:

> I like learnyouahaskell.com if you want to get some exposure to Haskell,
> probably the archetypal functional language these days.  I've been
> fooling with it on and off for the past couple years.  I'm still not
> convinced that it's that good a vehicle for practical general purpose
> software development, but there are some specific areas where it works
> out just beautifully.  And in terms of the challenges it presents and
> the amount I've learned from it, it's one of the most interesting things
> I've done as a programmer in as long as I can remember.  It really is
> mind altering.

Completely agree with you. Learnyouahaskell.com is as good as it gets
to learn haskell: haven't had so much fun learning a language since I
picked up python :-)

For similarly mind-altering pleasure, have a look at pure-lang [http://
code.google.com/p/pure-lang/] which describes itself as:

"Pure is a modern-style functional programming language based on term
rewriting. It offers equational definitions with pattern matching,
full symbolic rewriting capabilities, dynamic typing, eager and lazy
evaluation, lexical closures, built-in list and matrix support and an
easy-to-use C interface. The interpreter uses LLVM as a backend to JIT-
compile Pure programs to fast native code."

Enjoy!

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


Re: open(False) in python3

2010-05-12 Thread Johan Förberg
On Tue, 11 May 2010 19:27:37 -0300, Gabriel Genellina wrote:

> so open(False) is the same as open(0), and 0 is the file descriptor
> associated to standard input. The program isn't hung, it's just waiting
> for you to type some text

That's interesting. Are there any more numbered pseudofiles? I suppose 
its mainly an excellent way to confuse people when you open(0).read(), 
but it would be interesting to know.

Johan Förberg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: virtualenvwrapper for Windows (Powershell)

2010-05-12 Thread Guillermo
On May 12, 4:31 am, Lawrence D'Oliveiro  wrote:
> In message
> <973ca0fa-4a2f-4e3b-91b9-e38917885...@d27g2000yqc.googlegroups.com>,
>
> Guillermo wrote:
> > On May 11, 7:43 am, Lawrence D'Oliveiro 
> > wrote:
>
> >> In message
> >> <22cf35af-44d1-43fe-8b90-07f2c6545...@i10g2000yqh.googlegroups.com>,
>
> >> Guillermo wrote:
>
> >>> If you've ever missed it on Windows and you can use Powershell ...
>
> >> I thought the whole point of Windows was to get away from this
> >> command-line stuff. Not such a good idea after all?
>
> > I suppose it depends.
>
> On the way it’s implemented? Microsoft seems to have botched that as well.

File a bug then. It works here. But I think you're getting a wee bit
off-topic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to import a module for global use in a library package ?

2010-05-12 Thread Jean-Michel Pichavant

Terry Reedy wrote:

On 5/11/2010 8:04 AM, Auré Gourrier wrote:
I might make one submodule for imports and then do 'from rootlib.util 
import importmod as m' in the template. But I have no need now for such.


Terry Jan Reedy


We did that, and we so regret it. After 5 years of intensive dev on that 
application (with more than 10 different guys committing in the repos) 
this module is now nothing but a real mess.
As soon as someone is writing twice the same import: "Oh I should put 
this module into the auto import, it will save 4 sec of my time".


This module is now an inconsistent bunch of imports and global 
assignements  :( .


JM

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


Re: Extract all words that begin with x

2010-05-12 Thread Stefan Behnel

Bryan, 12.05.2010 08:55:

Now back to the arguably-interesting issue of speed in the particular
problem here: 'Superpollo' had suggested another variant, which I
appended to my timeit targets, resulting in:

[s for s in strs if s.startswith('a')]  took:  5.68393977159
[s for s in strs if s[:1] == 'a']  took:  3.31676491502
[s for s in strs if s and s[0] == 'a']  took:  2.29392950076

Superpollo's condition -- s and s[0] == 'a' -- is the fastest of the
three.


Just out of curiosity, I ran the same code in the latest Cython pre-0.13 
and added some optimised Cython implementations. Here's the code:


def cython_way0(l):
return [ s for s in l if s.startswith(u'a') ]

def cython_way1(list l):
cdef unicode s
return [ s for s in l if s.startswith(u'a') ]

def cython_way2(list l):
cdef unicode s
return [ s for s in l if s[:1] == u'a' ]

def cython_way3(list l):
cdef unicode s
return [ s for s in l if s[0] == u'a' ]

def cython_way4(list l):
cdef unicode s
return [ s for s in l if s and s[0] == u'a' ]

def cython_way5(list l):
cdef unicode s
return [ s for s in l if (s[0]) == u'a' ]

def cython_way6(list l):
cdef unicode s
return [ s for s in l if s and (s[0]) == u'a' ]


And here are the numbers (plain Python 2.6.5 first):

[s for s in strs if s.startswith(u'a')] took: 1.04618620872
[s for s in strs if s[:1] == u'a'] took: 0.518909931183
[s for s in strs if s and s[0] == u'a'] took: 0.617404937744

cython_way0(strs) took: 0.769457817078
cython_way1(strs) took: 0.0861849784851
cython_way2(strs) took: 0.208586931229
cython_way3(strs) took: 0.18615603447
cython_way4(strs) took: 0.190477132797
cython_way5(strs) took: 0.0366449356079
cython_way6(strs) took: 0.0368368625641

Personally, I think the cast to Py_UNICODE in the last two implementations 
shouldn't be required, that should happen automatically, so that way3/4 
runs equally fast as way5/6. I'll add that when I get to it.


Note that unicode.startswith() is optimised in Cython, so it's a pretty 
fast option, too. Also note that the best speed-up here is only a factor of 
14, so plain Python is quite competitive, unless the list is huge and this 
is really a bottleneck in an application.


Stefan

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


Re: virtualenvwrapper for Windows (Powershell)

2010-05-12 Thread Lawrence D'Oliveiro
In message
, 
Guillermo wrote:

> On May 12, 4:31 am, Lawrence D'Oliveiro 
> wrote:
>
>> In message
>> <973ca0fa-4a2f-4e3b-91b9-e38917885...@d27g2000yqc.googlegroups.com>,
>>
>> Guillermo wrote:
>> > On May 11, 7:43 am, Lawrence D'Oliveiro
>> >  wrote:
>>
>> >> In message
>> >> <22cf35af-44d1-43fe-8b90-07f2c6545...@i10g2000yqh.googlegroups.com>,
>>
>> >> Guillermo wrote:
>>
>> >>> If you've ever missed it on Windows and you can use Powershell ...
>>
>> >> I thought the whole point of Windows was to get away from this
>> >> command-line stuff. Not such a good idea after all?
>>
>> > I suppose it depends.
>>
>> On the way it’s implemented? Microsoft seems to have botched that as
>> well.
> 
> But I think you're getting a wee bit off-topic.

Hey, you were the one who brought it up.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open(False) in python3

2010-05-12 Thread Stefan Behnel

Johan Förberg, 12.05.2010 10:05:

On Tue, 11 May 2010 19:27:37 -0300, Gabriel Genellina wrote:


so open(False) is the same as open(0), and 0 is the file descriptor
associated to standard input. The program isn't hung, it's just waiting
for you to type some text


That's interesting. Are there any more numbered pseudofiles? I suppose
its mainly an excellent way to confuse people when you open(0).read(),
but it would be interesting to know.


Standard Unix behaviour dictates that 0 is stdin, 1 is stdout, and 2 is 
stderr. So you can only read() from 0.


Stefan

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


Re: open(False) in python3

2010-05-12 Thread Christian Heimes

Johan Förberg every:

That's interesting. Are there any more numbered pseudofiles? I suppose
its mainly an excellent way to confuse people when you open(0).read(),
but it would be interesting to know.


All opened files (and on Unix even network sockets, epoll queues, 
inotify handlers etc) have a number. It's called a file descriptor. By 
default stdin, stdout and stderr have the file descriptors 0, 1 and 2. 
The concept of file descriptors is much older than Python and not Python 
specific. Even shells use the numbers, e.g. "cmd >logfile 2>&1" means 
"write stdout to logfile, redirect and combine stderr stream with stdout".


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


Re: Extract all words that begin with x

2010-05-12 Thread Stefan Behnel

superpollo, 11.05.2010 17:03:

Aahz ha scritto:

In article ,
Terry Reedy  wrote:

On 5/10/2010 5:35 AM, James Mills wrote:

On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote:

Have I missed something, or wouldn't this work just as well:


list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
[word for word in list_of_strings if word[0] == 'a']

['awes', 'asdgas']

I would do this for completeness (just in case):


[word for word in list_of_strings if word and word[0] == 'a']

Just guards against empty strings which may or may not be in the list.

... word[0:1] does the same thing. All Python programmers should
learn to use slicing to extract a char from a string that might be
empty.
The method call of .startswith() will be slower, I am sure.


And if it is slower, so what? Using startswith() makes for faster
reading of the code for me, and I'm sure I'm not the only one.


also, what if the OP intended "words that begin with x" with x a string
(as opposed to a single character) ?


word[:len(x)] == x

will work in that case.

Stefan

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


Re: Extract all words that begin with x

2010-05-12 Thread superpollo

Stefan Behnel ha scritto:

superpollo, 11.05.2010 17:03:

Aahz ha scritto:

In article ,
Terry Reedy  wrote:

On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho 
wrote:

Have I missed something, or wouldn't this work just as well:


list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
[word for word in list_of_strings if word[0] == 'a']

['awes', 'asdgas']

I would do this for completeness (just in case):


[word for word in list_of_strings if word and word[0] == 'a']

Just guards against empty strings which may or may not be in the list.

... word[0:1] does the same thing. All Python programmers should
learn to use slicing to extract a char from a string that might be
empty.
The method call of .startswith() will be slower, I am sure.


And if it is slower, so what? Using startswith() makes for faster
reading of the code for me, and I'm sure I'm not the only one.


also, what if the OP intended "words that begin with x" with x a string
(as opposed to a single character) ?


word[:len(x)] == x

will work in that case.


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


client to upload big files via https and get progress info

2010-05-12 Thread News123
Hi,

I'd like to perform huge file uploads via https.
I'd like to make sure,
- that I can obtain upload progress info (sometimes the nw is very slow)
- that (if the file exceeds a certain size) I don't have to
  read the entire file into RAM.

I found Active states recipe 146306, which constructs the whole
multipart message first in RAM and sends it then in one chunk.


I found a server side solutions, that will write out the data file chunk
wise ( http://webpython.codepoint.net/mod_python_publisher_big_file_upload
)



If I just wanted to have progress info, then I could probably
just split line 16 of Active State's recipe ( h.send(body) )
into multiple send, right?

chunksize = 1024
for i in range(0,len(body),chunksize):
h.send(body[i:i+chunksize])
show_progressinfo()


But how could I create body step by step?
I wouldn't know the content-length up front?

thanks in advance



N





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


Re: Why the inconsistent of those two base64 methods?

2010-05-12 Thread Maarten
On May 12, 6:04 am, Leo Jay  wrote:
> I'd like to encode a string in base64, but I found a inconsistent of
> two methods:
>
> >>> 'aaa'.encode('base64')
> 'YWFh\n'
> >>> import base64
> >>> base64.b64encode('aaa')
> 'YWFh'
>
> as you can see, the result of
> 'aaa'.encode('base64')
> has a '\n' at the end, but the other method doesn't.
>
> Why the inconsistent?

Don't know. Does it matter?

>>> import base64
>>> base64.decodestring(base64.b64encode('aaa'))
'aaa'

>>> 'aaa'.encode('base64').decode('base64')
'aaa'

(so far so good, and as expected)

>>> base64.decodestring('aaa'.encode('base64'))
'aaa'

>>> base64.b64encode('aaa').decode('base64')
'aaa'

(As far as I can see, both methods are completely consistent)

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


Re: encoding issue (cp720)

2010-05-12 Thread Lie Ryan
On 05/12/10 18:43, M. Bashir Al-Noimi wrote:
> Hi All,
> 
> I'm still a newbie in Python (I started learn it yesterday)  and I faced
> a huge problem cuz python always crashes because of encoding issue!
> 
>> Fatal Python error: Py_Initialize: can't initialize sys standard streams
>> LookupError: unknown encoding: cp720
> 
> so I filed a bug report
> 
> about it but I couldn't find a solution for this problem so could you
> please help me to run python correctly?

This is partly a locale issue; your terminal (command prompt) is using a
locale yet unsupported by python. You can use 'chcp' to switch to
different terminal code page (e.g. use chcp 1250). You won't be able to
'print' arabic characters, but at least python should run.

> *Note:*
> 
>* I'm using: Windows XP SP3 32Bit, Python 3.1.2
>* I tried to copy cp720.py
>  
>  to Python31\Lib\encodings but it didn't fix the issue and gives me
>  an error message (see attachment plz)

You're using Python 3.1, the cp720.py file you copied is for Python 2.7
(trunk); there are some backward incompatible between python 2 and
python 3 (specifically in your case, unicode string is now default in
python 3, so unicode literal is no longer supported). Try using the
cp720.py from py3k branch:
http://svn.python.org/view/python/branches/py3k/Lib/encodings/cp720.py?view=markup
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange interaction between open and cwd

2010-05-12 Thread Albert van der Horst
In article ,
Grant Edwards   wrote:

>
>Still, at the time, it _seemed_ like a good way to share a directory
>of source code amongst multiple projects.  I don't remember why
>symlinks wouldn't accomplish the task -- something to do with RCS...

Must be deep. I use RCS in combination with symlinks all the time.
Like symlinks to a directory tree on a mounted volume, where
one is not supposed to check out.
Or symlinking  happyd.sco,v to HAPPYD.SCO,v effectively making
file names case-insensitive.

>
>--
>Grant
>

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re:[SOLVED] encoding issue (cp720)

2010-05-12 Thread M. Bashir Al-Noimi

Hi Lie,

On 12/05/2010 12:14 م, Lie Ryan wrote:

On 05/12/10 18:43, M. Bashir Al-Noimi wrote:
   

Hi All,

I'm still a newbie in Python (I started learn it yesterday)  and I faced
a huge problem cuz python always crashes because of encoding issue!

 

Fatal Python error: Py_Initialize: can't initialize sys standard streams
LookupError: unknown encoding: cp720
   

so I filed a bug report

about it but I couldn't find a solution for this problem so could you
please help me to run python correctly?
 

This is partly a locale issue; your terminal (command prompt) is using a
locale yet unsupported by python. You can use 'chcp' to switch to
different terminal code page (e.g. use chcp 1250). You won't be able to
'print' arabic characters, but at least python should run.
   
Actually I tried to run chcp (some one mentioned it in bug report) but 
it didn't fix the issue.



*Note:*

* I'm using: Windows XP SP3 32Bit, Python 3.1.2
* I tried to copy cp720.py
  
  to Python31\Lib\encodings but it didn't fix the issue and gives me
  an error message (see attachment plz)
 

You're using Python 3.1, the cp720.py file you copied is for Python 2.7
(trunk); there are some backward incompatible between python 2 and
python 3 (specifically in your case, unicode string is now default in
python 3, so unicode literal is no longer supported). Try using the
cp720.py from py3k branch:
http://svn.python.org/view/python/branches/py3k/Lib/encodings/cp720.py?view=markup
   

Thanks a lot python currently works this is the right file.

--
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net

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


Re: Iterating over dict and removing some elements

2010-05-12 Thread Adi Eyal
> -- Forwarded message --
> From: Bryan 
> To: [email protected]
> Date: Tue, 11 May 2010 23:59:29 -0700 (PDT)
> Subject: Re: Iterating over dict and removing some elements
> Terry Reedy wrote:
> [...]
>> for k in [k for k in d if d[k] == 'two']:
>>          d.pop(k)
>
> We have a winner.
>

also

foo = lambda k, d : d[k] == "two"
d = dict([(k, d[k]) for k in d.keys() if not foo(k, d)])

incidentally, this is marginally slower than pops and dels but has the
benefit of not modifying the original dict if that's what you need.

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


Re: Picking a license

2010-05-12 Thread Paul Boddie
On 11 Mai, 22:39, Patrick Maupin  wrote:
>
> OK.  Now I'm REALLY confused.  I said "Certainly RMS
> carefully lays out that the LGPL should be used sparingly in his "Why
> you shouldn't use the Lesser GPL for your next library" post.  (Hint:
> he's not suggesting a permissive license instead.)"
>
> to which you replied:
>
> "Sure, but all he's asking you to do is to make the software available
> under a GPL-compatible licence."

Alright, then, all he's asking you to do is to make *your* software
available under a GPL-compatible licence. That's what I meant in the
context of the discussion. Usually, people complain about how the GPL
dictates a single licence, forbidding all others, that is then
inseparable from their work ("It's my work but they make me GPL it! I
can't even control my own work any more! The FSF owns it!" and such
nonsense), but I've already given examples of this not being the case
at all.

> and then I tried to politely show that you were wrong about RMS's
> intentions, but now, but you're saying "oh, of course, he'd say that
> -- he wrote the license"  which is basically what I've been saying all
> along.  But if you have read it like you say, then it appears you were
> being very disingenuous in your original reply!

What the licence asks you to do and what the author of the licence
wants you to do are two separate things.

[...]

> NO.  If you are building an application, and distributing GPLed stuff
> as part of it, the FSF still maintains that the license is such that
> the entire application must be GPLed.  You keep acting like this isn't
> true, but it absolutely is if you're distributing the entire
> application.

I wrote "the software" above when I meant "your software", but I have
not pretended that the whole system need not be available under the
GPL. Otherwise the following text would be logically inconsistent with
such claims:

[...]

> On May 11, 5:24 am, Paul Boddie  wrote:
> > Again, you have to consider the intent of the licensing: that some
> > software which links to readline results in a software system that
> > should offer the "four freedoms", because that's the price of linking
> > to readline whose licence has promised that any system which builds
> > upon it shall offer those privileges.
>
> But I did consider the intent, and as I have made clear, I think
> that's a bullying tactic that fragments the software world
> unnecessarily.  Obviously YMMV.

More loaded terms to replace the last set, I see.

> > > > As for rst2pdf, what your modifications would mean is that the
> > > > software would need to be redistributed under a GPL-compatible
> > > > licence.
>
> NO.  You're still not paying attention.  The FSF's clear position is
> that if you actually *redistribute* software under the GPL as *part of
> a system* then the full package must be licensed *under the GPL*.

Again, what I meant was "your software", not the whole software
system. As I more or less state below...

> > Once again, I refer you to the intent of the licensing: if someone has
> > the software in front of them which uses svglib, then they need to
> > have the privileges granted to them by the GPL. Yes, if the software
> > also uses some component with a GPL-incompatible licence, then this
> > causes a problem.
>
> It appears that the FSF's position is the ability to link to svglib
> would require software to be licensed under the GPL.

It would require the resulting system to be licensed under the GPL. As
it stands by itself, rst2pdf would need to be licensed compatibly with
the GPL.

> I don't believe
> that, but I do believe that if rst2pdf distributed svglib (or even
> patches to svglib which were clearly derivative works) then yes,
> rst2pdf would have to be distributed under the GPL.  This kind of
> bullshit is only acceptable to people who only think a single license
> is acceptable.

Take it or leave it, then.

[...]

> > Well, I have referred several times to WebKit without you taking the
> > hint,
>
> OK, I don't work with webkit.  I knew you were hinting at something,
> but why the games, I don't know.  I guess it's all about mystique and
> games.

You mentioned WebKit as a non-GPL-licensed project which attracted
contributions from hard-nosed business. WebKit started life as KHTML
and was (and still is) LGPL-licensed, but for all practical purposes,
KHTML was only ever experienced by KDE users whilst linked to the Qt
framework, then available under the GPL. Now, given that WebKit now
works with other GUI frameworks, yet is still LGPL-licensed (and this
has nothing to do with recent Qt licensing developments, since this
applies to the period before those changes), it is clear that any
assertion that WebKit "was made GPL-only", which is what a lot of
people claim, is incorrect.

> > but that provides a specific case of a project which is LGPL-
> > licensed despite being based on (in GPLv3 terminology) libraries which
> > were distributed under the GPL and combined with that software.
>
> W

Re: Picking a license

2010-05-12 Thread Paul Boddie
On 11 Mai, 23:02, Patrick Maupin  wrote:
>
> Huh? Permissive licenses offer much better certainty for someone
> attempting a creative mash-up.  Different versions of the Apache
> license don't conflict with each other.  If I use an MIT-licensed
> component, it doesn't attempt to make me offer my whole work under
> MIT.

What certainty does the MIT licence give contributors to a project
against patent infringement claims initiated by another contributor?

[...]

> Oh, I get it.  You were discussing the certainty that an author can
> control what downstream users do with the software to some extent.
> Yes, I fully agree.  The GPL is for angry idealists who have an easily
> outraged sense of justice, who don't have enough real problems to work
> on.

Again, the author does not exercise control when people must
voluntarily choose to use that author's work and thereby agree to
adhere to that author's set of terms.

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


Re: Picking a license

2010-05-12 Thread Paul Boddie
On 11 Mai, 22:50, Patrick Maupin  wrote:
> On May 11, 5:34 am, Paul Boddie  wrote:
>
> > Yes, *if* you took it. He isn't forcing you to take it, though, is he?
>
> No,  but he said a lot of words that I didn't immediately understand
> about what it meant to be free and that it was free, and then after I
> bit into it he told me he owned my soul now.

Thus, "owned my soul" joins "holy war" and "Bin Laden" on the list.
That rhetorical toolbox is looking pretty empty at this point.

[...]

> > It is whining if someone says, "I really want that chocolate, but that
> > nasty man is going to make me pay for it!"
>
> But that's not what happened.  I mean, he just told me that I might
> have to give some of it to others later.  He didn't mention that if I
> spread peanut butter on mine before I ate it that I'd have to give
> people Reese's Peanut Butter cups.

He isn't, though. He's telling you that you can't force other people
to lick the chocolate off whatever "Reese's Peanut Butter cups" are,
rather than actually eating the combination of the two, when you offer
such a combination to someone else. Is the Creative Commons share-
alike clause just as objectionable to you, because it's that principle
we're talking about here?

[...]

> > If the man said, "please take the chocolate, but I want you to share
> > it with your friends", and you refused to do so because you couldn't
> > accept that condition, would it be right to say, "that man is forcing
> > me to share chocolate with my friends"?
>
> But the thing is, he's *not* making me share the chocolate with any of
> my friends.  He's not even making me share my special peanut butter
> and chocolate.  What he's making me do is, if I give my peanut butter
> and chocolate to one of my friends, he's making me make *that* friend
> promise to share.  I try not to impose obligations like that on my
> friends, so obviously the "nice" man with the chocolate isn't my
> friend!

Yes, he's making everyone commit to sharing, and yes, it's like a
snowball effect once people agree to join in. But unless you hide that
commitment, no-one imposes anything on anyone. They can get their
chocolate elsewhere. They join in; they are not conscripted.

[...]

> I explained this very carefully before multiple times.  Let me give
> concrete examples -- (1) I have told my children before "if we take
> that candy, then they will make us pay for it" and (2) if we included
> (GPLed software) in this (MIT-licensed software) then we will have to
> change the license.  In both these cases, once the decision has been
> made, then yes, force enters into it.  And no, I don't think the
> average shop keeper is nearly as evil as Darth, or even RMS.

Entering an agreement voluntarily does not mean that you are forced to
enter that agreement, even if the agreement then involves obligations
(as agreements inevitably do).

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


How to add callbacks that is the same function with different argument in Tkinter python26?

2010-05-12 Thread chen zeguang
code is in the end.
I want to print different number when pressing different button.
Yet the program outputs 8 no matter which button is pressed.
I guess it's because the callback function is not established untill the
button is pressed, and i has already reached to 8.

then How to add callbacks that is the same function with different argument?

CODE:
from Tkinter import *
root = Tk()
def func(x):
print x
return

func_en=[]
for i in range(9):
func_en.append(lambda:func(i))
for i in range(9):
func_en[i]()
for i in range(9):
Button(root, text='%d'%i, command=func_en[i]).pack()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to add callbacks that is the same function with different argument in Tkinter python26?

2010-05-12 Thread Jean-Michel Pichavant

chen zeguang wrote:

code is in the end.
I want to print different number when pressing different button.
Yet the program outputs 8 no matter which button is pressed.
I guess it's because the callback function is not established untill 
the button is pressed, and i has already reached to 8.


then How to add callbacks that is the same function with different 
argument?


CODE:
from Tkinter import *
root = Tk()
def func(x):
print x
return

func_en=[]
for i in range(9):
func_en.append(lambda:func(i))
for i in range(9):
func_en[i]()
for i in range(9):
Button(root, text='%d'%i, command=func_en[i]).pack()

from Tkinter import *
root = Tk()

def func(x):
   def _printme():
   print x
   return _printme

for i in range(9):
   Button(root, text='%d'%i, command=func(i)).pack()

Surely someone will explain why your code was not working, I can't 
'cause I don't use lambda, it brings more problems than it solves (maybe 
I'm not talented enough).
Above is how I would have written the code, I tested it, looks like it's 
working.


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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 7:10 am, Paul Boddie  wrote:
> On 11 Mai, 22:39, Patrick Maupin  wrote:
>
>
>
> > OK.  Now I'm REALLY confused.  I said "Certainly RMS
> > carefully lays out that the LGPL should be used sparingly in his "Why
> > you shouldn't use the Lesser GPL for your next library" post.  (Hint:
> > he's not suggesting a permissive license instead.)"
>
> > to which you replied:
>
> > "Sure, but all he's asking you to do is to make the software available
> > under a GPL-compatible licence."
>
> Alright, then, all he's asking you to do is to make *your* software
> available under a GPL-compatible licence. That's what I meant in the
> context of the discussion. Usually, people complain about how the GPL
> dictates a single licence, forbidding all others, that is then
> inseparable from their work ("It's my work but they make me GPL it! I
> can't even control my own work any more! The FSF owns it!" and such
> nonsense), but I've already given examples of this not being the case
> at all.

In that post, specifically, RMS says to use the GPL in some cases,
rather than the LGPL, for libraries.  Any other interpretation of
*that post* is disingenuous.

> > and then I tried to politely show that you were wrong about RMS's
> > intentions, but now, but you're saying "oh, of course, he'd say that
> > -- he wrote the license"  which is basically what I've been saying all
> > along.  But if you have read it like you say, then it appears you were
> > being very disingenuous in your original reply!
>
> What the licence asks you to do and what the author of the licence
> wants you to do are two separate things.

But the whole context was about what RMS wanted me to do and you
disagreed!

>
> > NO.  If you are building an application, and distributing GPLed stuff
> > as part of it, the FSF still maintains that the license is such that
> > the entire application must be GPLed.  You keep acting like this isn't
> > true, but it absolutely is if you're distributing the entire
> > application.
>
> I wrote "the software" above when I meant "your software", but I have
> not pretended that the whole system need not be available under the
> GPL.

You say you "have not pretended" but you've never mentioned that it
would or even acknowledged the correctness of my assertions about this
until now, just claiming that what I said was false.

> > On May 11, 5:24 am, Paul Boddie  wrote:
> > > Again, you have to consider the intent of the licensing: that some
> > > software which links to readline results in a software system that
> > > should offer the "four freedoms", because that's the price of linking
> > > to readline whose licence has promised that any system which builds
> > > upon it shall offer those privileges.
>
> > But I did consider the intent, and as I have made clear, I think
> > that's a bullying tactic that fragments the software world
> > unnecessarily.  Obviously YMMV.
>
> More loaded terms to replace the last set, I see.

IMO "Bullying" is the correct term for some of Stallman's actions,
including in the clisp debacle.  I knew you wouldn't agree -- that's
why YMMV.  And I'm not "replacing" any set of terms -- part of the
"bullying" is the "forcing."

> > > > > As for rst2pdf, what your modifications would mean is that the
> > > > > software would need to be redistributed under a GPL-compatible
> > > > > licence.
>
> > NO.  You're still not paying attention.  The FSF's clear position is
> > that if you actually *redistribute* software under the GPL as *part of
> > a system* then the full package must be licensed *under the GPL*.
>
> Again, what I meant was "your software", not the whole software
> system. As I more or less state below...

BUT THAT DOESN'T MATTER.  Once the whole package is licensed under the
GPL, for someone downstream to try to scrape the GPL off and get to
just the underlying non-GPL parts is harder than scraping bubblegum
off your shoe on a hot Texas day.

> > > Once again, I refer you to the intent of the licensing: if someone has
> > > the software in front of them which uses svglib, then they need to
> > > have the privileges granted to them by the GPL. Yes, if the software
> > > also uses some component with a GPL-incompatible licence, then this
> > > causes a problem.
>
> > It appears that the FSF's position is the ability to link to svglib
> > would require software to be licensed under the GPL.
>
> It would require the resulting system to be licensed under the GPL. As
> it stands by itself, rst2pdf would need to be licensed compatibly with
> the GPL.

They've softened their stance considerably over the last few years,
and don't overreach nearly as much as they used to, I agree.

[...]

> You mentioned WebKit as a non-GPL-licensed project which attracted
> contributions from hard-nosed business. WebKit started life as KHTML
> and was (and still is) LGPL-licensed, but for all practical purposes,
> KHTML was only ever experienced by KDE users whilst linked to the Qt
> framework, then available under th

Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 11, 10:06 pm, Lie Ryan  wrote:

> The point is, GPL (and OWL) is for programmers who just don't care about
> the legal stuffs and would want to spend more time writing code than
> writing license.

Absolutely.  When I wrote "permissive license" I was not trying to
imply that everybody should roll their own.

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


Need help using callables and setup in timeit.Timer

2010-05-12 Thread Matthew Wilson
I want to time some code that depends on some setup.  The setup code
looks a little like this:

>>> b = range(1, 1001)

And the code I want to time looks vaguely like this:

>>> sorted(b)

Except my code uses a different function than sorted.  But that ain't
important right now.

Anyhow, I know how to time this code as long as I pass in strings to timeit:

>>> import timeit
>>> t = timeit.Timer("sorted(b)", "b = range(1, 1001)")
>>> min(t.repeat(3, 100))

How do I use a setup callable and have it put stuff into the namespace
that the stmt callable can access?

In other words, I want to do the same thing as above, but using
callables as the parameters to timeit.Timer, not strings of python code.

Here's my long-run goal.  I want to reuse code from my unit tests to
test performance:

import unittest
class TestSorting(unittest.TestCase):

def setUp(self):
self.b = range(1, 1001)

def test_sorted(self):
sorted(self.b)

I expect to have to do a little work.  The timeit setup will need to
make an instance of TestSorting and somehow the stmt code will have to
use that particular instance.

Once I understand how to have the timeit setup put stuff into the same
namespace as the timeit stmt, I'll attack how to translate
unittest.TestCase instances into something that can feed right into
timeit.Timer.

Matt



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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 7:26 am, Paul Boddie  wrote:
> On 11 Mai, 23:02, Patrick Maupin  wrote:
> > Huh? Permissive licenses offer much better certainty for someone
> > attempting a creative mash-up.  Different versions of the Apache
> > license don't conflict with each other.  If I use an MIT-licensed
> > component, it doesn't attempt to make me offer my whole work under
> > MIT.
>
> What certainty does the MIT licence give contributors to a project
> against patent infringement claims initiated by another contributor?

None.  If I was worried about that, I'd probably use the Apache
license instead.

> > Oh, I get it.  You were discussing the certainty that an author can
> > control what downstream users do with the software to some extent.
> > Yes, I fully agree.  The GPL is for angry idealists who have an easily
> > outraged sense of justice, who don't have enough real problems to work
> > on.
>
> Again, the author does not exercise control when people must
> voluntarily choose to use that author's work and thereby agree to
> adhere to that author's set of terms.

So you're saying that Microsoft doesn't exercise control about keeping
me from using a copy of Windows on more than one machine -- it's not
"control" because I agreed to it up front.   Sorry, my mileage
varies.  In fact, I would (and do) say that Microsoft forces me to buy
one copy of Windows for every machine I want to run it on.

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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 7:43 am, Paul Boddie  wrote:
> On 11 Mai, 22:50, Patrick Maupin  wrote:
>
> > On May 11, 5:34 am, Paul Boddie  wrote:
>
> > > Yes, *if* you took it. He isn't forcing you to take it, though, is he?
>
> > No,  but he said a lot of words that I didn't immediately understand
> > about what it meant to be free and that it was free, and then after I
> > bit into it he told me he owned my soul now.
>
> Thus, "owned my soul" joins "holy war" and "Bin Laden" on the list.
> That rhetorical toolbox is looking pretty empty at this point.

Not emptier than you analogy toolbox.  This is really a pretty stupid
analogy, but I guess my lame attempts at showing that are wasted.

> > > It is whining if someone says, "I really want that chocolate, but that
> > > nasty man is going to make me pay for it!"
>
> > But that's not what happened.  I mean, he just told me that I might
> > have to give some of it to others later.  He didn't mention that if I
> > spread peanut butter on mine before I ate it that I'd have to give
> > people Reese's Peanut Butter cups.
>
> He isn't, though. He's telling you that you can't force other people
> to lick the chocolate off whatever "Reese's Peanut Butter cups" are,
> rather than actually eating the combination of the two, when you offer
> such a combination to someone else.

No.  That's not what is happening, and you've now officially stretched
the analogy way past the breaking point.  In any case, he's telling me
I have to give the recipe for my homemade peanut butter.

> Is the Creative Commons share-
> alike clause just as objectionable to you, because it's that principle
> we're talking about here?

I have explained that, in some cases, I will use GPL software, and in
other cases I won't, and tried to explain why and what the difference
is.  Anybody can re-read my posts and figure out that the same might
apply to the various Creative Commons licenses.

> > > If the man said, "please take the chocolate, but I want you to share
> > > it with your friends", and you refused to do so because you couldn't
> > > accept that condition, would it be right to say, "that man is forcing
> > > me to share chocolate with my friends"?
>
> > But the thing is, he's *not* making me share the chocolate with any of
> > my friends.  He's not even making me share my special peanut butter
> > and chocolate.  What he's making me do is, if I give my peanut butter
> > and chocolate to one of my friends, he's making me make *that* friend
> > promise to share.  I try not to impose obligations like that on my
> > friends, so obviously the "nice" man with the chocolate isn't my
> > friend!
>
> Yes, he's making everyone commit to sharing, and yes, it's like a
> snowball effect once people agree to join in.

Sorry, I sometimes have a hard time distinguishing the semantic
difference between "make" and "force".  Could you elucidate?

> But unless you hide that
> commitment, no-one imposes anything on anyone. They can get their
> chocolate elsewhere. They join in; they are not conscripted.

And I've already explained why, in some cases, someone might refuse
the tastiest chocolate in the world to not join in.

> > I explained this very carefully before multiple times.  Let me give
> > concrete examples -- (1) I have told my children before "if we take
> > that candy, then they will make us pay for it" and (2) if we included
> > (GPLed software) in this (MIT-licensed software) then we will have to
> > change the license.  In both these cases, once the decision has been
> > made, then yes, force enters into it.  And no, I don't think the
> > average shop keeper is nearly as evil as Darth, or even RMS.
>
> Entering an agreement voluntarily does not mean that you are forced to
> enter that agreement, even if the agreement then involves obligations
> (as agreements inevitably do).

No, but copyright licenses are funny things, not like contracts where
there is a meeting of the minds up front.  For example, while the
Ciscos of the world have no excuse, I bet a lot of people who download
Ubuntu and make copies for their friends are unaware of this section
of the GPL FAQ:

"I downloaded just the binary from the net. If I distribute copies, do
I have to get the source and distribute that too?   Yes. The general
rule is, if you distribute binaries, you must distribute the complete
corresponding source code too. The exception for the case where you
received a written offer for source code is quite limited."

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


Re: Upgrade Python 2.6.4 to 2.6.5

2010-05-12 Thread Michel Claveau - MVP
Hi! 

If you are under Vista, or Windows 7, have you unactivate UAC, before
the update?

@+

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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 2:19 am, Lie Ryan  wrote:
> On 05/12/10 06:50, Patrick Maupin wrote:
>
>
>
> > On May 11, 5:34 am, Paul Boddie  wrote:
> >> On 10 Mai, 20:36, Patrick Maupin  wrote:
> >>>  The fact is, I know the man would force me to pay for the chocolate, so 
> >>> in
> >>> some cases that enters into the equation and keeps me from wanting the
> >>> chocolate.
>
> >> If the man said, "please take the chocolate, but I want you to share
> >> it with your friends", and you refused to do so because you couldn't
> >> accept that condition, would it be right to say, "that man is forcing
> >> me to share chocolate with my friends"?
>
> > But the thing is, he's *not* making me share the chocolate with any of
> > my friends.  He's not even making me share my special peanut butter
> > and chocolate.  What he's making me do is, if I give my peanut butter
> > and chocolate to one of my friends, he's making me make *that* friend
> > promise to share.  I try not to impose obligations like that on my
> > friends, so obviously the "nice" man with the chocolate isn't my
> > friend!
>
> The analogy breaks here; unlike chocolate, the value of software/source
> code, if shared, doesn't decrease (in fact, many software increases its
> value when shared liberally, e.g. p2p apps).

Absolutely true. Actually, the analogy was really pretty broken to
start with.  It wasn't my analogy -- I was just trying to play
along :-)

> There might be certain cases where the software contains some trade
> secret whose value decreases the more people knows about it; but sharing
> does not decrease the value of the software, at least not directly, it
> is the value of the secret that decreases because of the sharing.

Sure.  But in general, people will share, often even when doing so is
legally questionable.  Just look at the RIAA's woes if you don't
believe me.  The only real question here is whether the marginal value
achieved by adding constraints to force people to share (which most
would have done anyway) outweighs the costs to people who, for
whatever reason (perhaps a trade secret obligation) *can't* share.

The answer to that question may well vary depending on several
factors.  The fact that GPL and Apache and MIT and BSD are available
is a good thing -- whichever license an author feels best fits his
project is definitely the one he should use.

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


Re: How to add callbacks that is the same function with different argument in Tkinter python26?

2010-05-12 Thread Dave Angel

Jean-Michel Pichavant wrote:

chen zeguang wrote:

code is in the end.
I want to print different number when pressing different button.
Yet the program outputs 8 no matter which button is pressed.
I guess it's because the callback function is not established untill 
the button is pressed, and i has already reached to 8.


then How to add callbacks that is the same function with different 
argument?


CODE:
from Tkinter import *
root = Tk()
def func(x):
print x
return

func_en=[]
for i in range(9):
func_en.append(lambda:func(i))
for i in range(9):
func_en[i]()
for i in range(9):
Button(root, text='%d'%i, command=func_en[i]).pack()

from Tkinter import *
root = Tk()

def func(x):
   def _printme():
   print x
   return _printme

for i in range(9):
   Button(root, text='%d'%i, command=func(i)).pack()

Surely someone will explain why your code was not working, I can't 
'cause I don't use lambda, it brings more problems than it solves 
(maybe I'm not talented enough).
Above is how I would have written the code, I tested it, looks like 
it's working.


JM
This solution works because of the nested function.  Chen could do the 
same with nested lambdas, or by using default arguments in the lambda.


The trick is just that you need separate instances of x for each 
callback, so they don't all get incremented in the loop.


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


Re: Extract all words that begin with x

2010-05-12 Thread Aahz
In article ,
Stefan Behnel   wrote:
>superpollo, 11.05.2010 17:03:
>> Aahz ha scritto:
>>> In article ,
>>> Terry Reedy  wrote:
 On 5/10/2010 5:35 AM, James Mills wrote:
> On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote:
>> Have I missed something, or wouldn't this work just as well:
>>
> list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
> [word for word in list_of_strings if word[0] == 'a']
>> ['awes', 'asdgas']
> I would do this for completeness (just in case):
>
> [word for word in list_of_strings if word and word[0] == 'a']
> Just guards against empty strings which may or may not be in the list.
 ... word[0:1] does the same thing. All Python programmers should
 learn to use slicing to extract a char from a string that might be
 empty.
 The method call of .startswith() will be slower, I am sure.
>>>
>>> And if it is slower, so what? Using startswith() makes for faster
>>> reading of the code for me, and I'm sure I'm not the only one.
>>
>> also, what if the OP intended "words that begin with x" with x a string
>> (as opposed to a single character) ?
>
> word[:len(x)] == x
>
>will work in that case.

But that's now going to be slower.  ;-)  (Unless one makes the obvious
optimization to hoist len(x) out of the loop.)
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extract all words that begin with x

2010-05-12 Thread Stefan Behnel

Aahz, 12.05.2010 17:33:

Stefan Behnel  wrote:

superpollo, 11.05.2010 17:03:

Aahz ha scritto:

In article,
Terry Reedy  wrote:

On 5/10/2010 5:35 AM, James Mills wrote:

On Mon, May 10, 2010 at 6:50 PM, Xavier Ho  wrote:

Have I missed something, or wouldn't this work just as well:


list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
[word for word in list_of_strings if word[0] == 'a']

['awes', 'asdgas']

I would do this for completeness (just in case):


[word for word in list_of_strings if word and word[0] == 'a']

Just guards against empty strings which may or may not be in the list.

... word[0:1] does the same thing. All Python programmers should
learn to use slicing to extract a char from a string that might be
empty.
The method call of .startswith() will be slower, I am sure.


And if it is slower, so what? Using startswith() makes for faster
reading of the code for me, and I'm sure I'm not the only one.


also, what if the OP intended "words that begin with x" with x a string
(as opposed to a single character) ?


 word[:len(x)] == x

will work in that case.


But that's now going to be slower.  ;-)  (Unless one makes the obvious
optimization to hoist len(x) out of the loop.)


Right, I forgot to mention that I left that as an exercise to the reader.

Stefan

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


Re: Extract all words that begin with x

2010-05-12 Thread Terry Reedy

On 5/12/2010 11:33 AM, Aahz wrote:


also, what if the OP intended "words that begin with x" with x a string
(as opposed to a single character) ?


 word[:len(x)] == x

will work in that case.


But that's now going to be slower.  ;-)  (Unless one makes the obvious
optimization to hoist len(x) out of the loop.)


If x were a known literal, then len(x) could be replaced by the actual 
size. But I admit that that is a nuisance and point of failure. I think 
comparing start/end strings of variable length or length greater than 
one is the real justification for the new methods, not the OP's trivial 
single-char case.


Terry Jan Reedy



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


Re: open(False) in python3

2010-05-12 Thread geremy condra
On Wed, May 12, 2010 at 1:36 AM, Stefan Behnel  wrote:
> Johan Förberg, 12.05.2010 10:05:
>>
>> On Tue, 11 May 2010 19:27:37 -0300, Gabriel Genellina wrote:
>>
>>> so open(False) is the same as open(0), and 0 is the file descriptor
>>> associated to standard input. The program isn't hung, it's just waiting
>>> for you to type some text
>>
>> That's interesting. Are there any more numbered pseudofiles? I suppose
>> its mainly an excellent way to confuse people when you open(0).read(),
>> but it would be interesting to know.
>
> Standard Unix behaviour dictates that 0 is stdin, 1 is stdout, and 2 is
> stderr. So you can only read() from 0.
>
> Stefan

Nitpicking, but open(1).read() and open(2).read() both succeed
(for small values of success) the same way that open(0).read()
does.

Thanks for the advice, everybody.

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


Re: Why the inconsistent of those two base64 methods?

2010-05-12 Thread Mensanator
On May 12, 4:20 am, Maarten  wrote:
> On May 12, 6:04 am, Leo Jay  wrote:
>
> > I'd like to encode a string in base64, but I found a inconsistent of
> > two methods:
>
> > >>> 'aaa'.encode('base64')
> > 'YWFh\n'
> > >>> import base64
> > >>> base64.b64encode('aaa')
> > 'YWFh'
>
> > as you can see, the result of
> > 'aaa'.encode('base64')
> > has a '\n' at the end, but the other method doesn't.
>
> > Why the inconsistent?
>
> Don't know. Does it matter?

Yeah...

>>> import base64
>>> a = 'aaa'.encode('base64')
>>> aa = base64.b64encode('aaa')
>>> a == aa
False


>
> >>> import base64
> >>> base64.decodestring(base64.b64encode('aaa'))
>
> 'aaa'
>
> >>> 'aaa'.encode('base64').decode('base64')
>
> 'aaa'
>
> (so far so good, and as expected)
>
> >>> base64.decodestring('aaa'.encode('base64'))
>
> 'aaa'
>
> >>> base64.b64encode('aaa').decode('base64')
>
> 'aaa'
>
> (As far as I can see, both methods are completely consistent)

Your notion of 'consistency' is wanting.

>
> Maarten

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


Re: Picking a license

2010-05-12 Thread Paul Boddie
On 12 Mai, 16:45, Patrick Maupin  wrote:
> On May 12, 7:43 am, Paul Boddie  wrote:
> > Thus, "owned my soul" joins "holy war" and "Bin Laden" on the list.
> > That rhetorical toolbox is looking pretty empty at this point.
>
> Not emptier than you analogy toolbox.  This is really a pretty stupid
> analogy, but I guess my lame attempts at showing that are wasted.

Yes they are. The analogy was to point out that someone can really
want something, but if they are not prepared to accept the "price" of
acquiring it, then there is no point in them whining about someone
withholding that thing from them, or whining about someone "forcing"
them to do stuff, especially when there is clearly no "force" involved
at all.

[...]

> > He isn't, though. He's telling you that you can't force other people
> > to lick the chocolate off whatever "Reese's Peanut Butter cups" are,
> > rather than actually eating the combination of the two, when you offer
> > such a combination to someone else.
>
> No.  That's not what is happening, and you've now officially stretched
> the analogy way past the breaking point.  In any case, he's telling me
> I have to give the recipe for my homemade peanut butter.

If you want to redefine the basis of the analogy, then you can talk
about the recipe all you like, yes. Otherwise, no: the analogy was
only about people whining about not being able to get stuff with no
strings attached. I could swap that analogy with one that has someone
really wanting a ride on a bus, or wanting to go to the moon, where
they don't like it when someone tells them that they can't get do that
stuff without agreeing to something or other first. Feel free to start
discussing the shape of the bus ticket or who pays for spacesuits if
you want, but to say, "I really want to use that thing, but that nasty
man has licensed it under the GPL" is whining in precisely the same
way as featured in the analogy.

> > Is the Creative Commons share-
> > alike clause just as objectionable to you, because it's that principle
> > we're talking about here?
>
> I have explained that, in some cases, I will use GPL software, and in
> other cases I won't, and tried to explain why and what the difference
> is.  Anybody can re-read my posts and figure out that the same might
> apply to the various Creative Commons licenses.

So it is objectionable to you as well, then.

[...]

> > Yes, he's making everyone commit to sharing, and yes, it's like a
> > snowball effect once people agree to join in.
>
> Sorry, I sometimes have a hard time distinguishing the semantic
> difference between "make" and "force".  Could you elucidate?

Yes: once they've agreed to join in, they "have to" go along with the
whole scheme.

> > But unless you hide that
> > commitment, no-one imposes anything on anyone. They can get their
> > chocolate elsewhere. They join in; they are not conscripted.
>
> And I've already explained why, in some cases, someone might refuse
> the tastiest chocolate in the world to not join in.

Well, great for them. I thought they were "forced" to join in. I guess
not.

[...]

> No, but copyright licenses are funny things, not like contracts where
> there is a meeting of the minds up front.  For example, while the
> Ciscos of the world have no excuse, I bet a lot of people who download
> Ubuntu and make copies for their friends are unaware of this section
> of the GPL FAQ:
>
> "I downloaded just the binary from the net. If I distribute copies, do
> I have to get the source and distribute that too?   Yes. The general
> rule is, if you distribute binaries, you must distribute the complete
> corresponding source code too. The exception for the case where you
> received a written offer for source code is quite limited."

Yes, and that's why, when Mepis Linux were found not to be
distributing the sources, they had to go along with the above section.
And that's also why version 3 of the GPL has a clause about nominating
a party that will honour the obligation to provide source. But what's
your problem exactly? The GPL applies to redistribution, and the
default state of a copyrighted work is that you don't have permission
to redistribute it, so before someone shares something they have to
know whether they are able to do so or not.

The various clauses are all there for their own reasons. If you don't
like them, don't use GPL-licensed software.

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


Re: open(False) in python3

2010-05-12 Thread Giampaolo Rodolà
2010/5/12 Gabriel Genellina :
> open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
> builtin open() + os.fdopen() from 2.x all merged together. It does different
> things depending on the type and quantity of its arguments, and even returns
> objects of different types.
>
> In particular, open(some_integer) assumes some_integer is a file descriptor
> and return some variant of file object using the given file descriptor.

Interesting. I wasn't aware of this.
Is it documented somewhere?


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
-- 
http://mail.python.org/mailman/listinfo/python-list


Do any debuggers support "edit and continue?"

2010-05-12 Thread Joel Koltner
Just curious... in Microsoft's Visual Studio (and I would presume some other 
tools), for many languages (both interpreted and compiled!) there's an "edit 
and conitnue" option that, when you hit a breakpoint, allows you to modify a 
line of code before it's actually executed.


Does any Python debugger support this feature?  Being an interpreted language 
it doesn't seem like it would necessarily be too onerous to support?  It'd be 
quite handy in that, especially if you hit a breakpoint due to the interpreter 
throwing an error, you could fix just the line in question and keep going, 
rather than having to stop the entire program, fix the line, and then run 
again and potentially kill a bunch of time getting the program back into the 
same "state."


Thanks,
---Joel Koltner

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


RE: Do any debuggers support "edit and continue?"

2010-05-12 Thread Sandy Sandy

good question
I also looking for debugging tools like Matlab in Python

do you know how to stop in breakpoint investigate the variables by using 
graphics in  figures and continue
the
mutter is:

during debugging the  debug processes stacks when fig is created

for example, in code

import random

import matplotlib.pyplot as plt

from pylab import *

x= 23;

y = 11;

print(23456)

plt.plot(range(10))

plot([1,2,3])

show()

print()

a=888



it is impossible after show() to continue debug

as stated in

Beginning Python Visualization - Crafting Visual Transformation Scripts (2009)

page  187



Note If you’re not using matplotlib interactively in Python, be sure

to call the function show() after all

graphs have been generated, as it enters a user interface main loop

that will stop execution of the rest of

your code. The reason behind this behavior is that matplotlib is

designed to be embedded in a GUI as well.

In Windows, if you’re working from interactive Python, you need only

issue show() once; close the figures

(or figures) to return to the shell. Subsequent plots will be drawn

automatically without issuing show(), and

you’ll be able to plot graphs interactively.




the problem is that after show() the debugger stacks

the decision can be to use threads like this 

from pylab import plot,show,ion
ion()
x = range(10)
plot(x)
from threading import Timer
t = Timer(0, show)
t.start()

a = 133
y = [2, 8, 3, 9, 4]
plot(y)

zz= 12346
print(4)




but it is not working, bug??

Sandy
  

> From: [email protected]
> Subject: Do any debuggers support "edit and continue?"
> Date: Wed, 12 May 2010 10:42:31 -0700
> To: [email protected]
> 
> Just curious... in Microsoft's Visual Studio (and I would presume some other 
> tools), for many languages (both interpreted and compiled!) there's an "edit 
> and conitnue" option that, when you hit a breakpoint, allows you to modify a 
> line of code before it's actually executed.
> 
> Does any Python debugger support this feature?  Being an interpreted language 
> it doesn't seem like it would necessarily be too onerous to support?  It'd be 
> quite handy in that, especially if you hit a breakpoint due to the 
> interpreter 
> throwing an error, you could fix just the line in question and keep going, 
> rather than having to stop the entire program, fix the line, and then run 
> again and potentially kill a bunch of time getting the program back into the 
> same "state."
> 
> Thanks,
> ---Joel Koltner
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-12 Thread Paul Boddie
On 12 Mai, 16:10, Patrick Maupin  wrote:
> On May 12, 7:10 am, Paul Boddie  wrote:
> > What the licence asks you to do and what the author of the licence
> > wants you to do are two separate things.
>
> But the whole context was about what RMS wanted me to do and you
> disagreed!

What RMS as an activist wants is that everyone releases GPL-licensed
code, except where permissively licensed code might encourage open
standards proliferation. What RMS the licence author requests is that
your work is licensed in a way which is compatible with the GPL.

[...]

> > I wrote "the software" above when I meant "your software", but I have
> > not pretended that the whole system need not be available under the
> > GPL.
>
> You say you "have not pretended" but you've never mentioned that it
> would or even acknowledged the correctness of my assertions about this
> until now, just claiming that what I said was false.

Well, excuse me! I think we both know that combining something with a
GPL-licensed work and redistributing it means that the "four freedoms"
must apply, and that recipients get the work under the GPL. You can
insist that I said something else, but I spell it out in this post:

http://groups.google.com/group/comp.lang.python/msg/034fbc8289a4d555

Specifically the part...

"Not least because people are only obliged to make their work
available under a GPL-compatible licence so that people who are using
the combined work may redistribute it under
the GPL."

In case you don't find this satisfactory, "their work" means "their
own work".

[...]

> > More loaded terms to replace the last set, I see.
>
> IMO "Bullying" is the correct term for some of Stallman's actions,
> including in the clisp debacle.  I knew you wouldn't agree -- that's
> why YMMV.  And I'm not "replacing" any set of terms -- part of the
> "bullying" is the "forcing."

Stallman gave Haible the choice to not use readline. Maybe that wasn't
very nice, and maybe Haible didn't believe that using readline would
incur any consequences, but that's what you get when you use a
copyrighted work. Your language is all about portraying the FSF as
operating in some kind of illegal or unethical way. I guess you
believe that if you throw enough mud, some of it will stick.

> > Again, what I meant was "your software", not the whole software
> > system. As I more or less state below...
>
> BUT THAT DOESN'T MATTER.  Once the whole package is licensed under the
> GPL, for someone downstream to try to scrape the GPL off and get to
> just the underlying non-GPL parts is harder than scraping bubblegum
> off your shoe on a hot Texas day.

Big deal. If a project wants to avoid even looking at GPL-licensed
code for the reason that someone might end up getting the code under
the GPL, and that they're so bothered that the opportunity to not
grant such recipients the privileges of modification and
redistribution disappears because of the GPL, then that's their
problem.

[WebKit is LGPL-licensed but KHTML linked to GPL-licensed code,
shouldn't WebKit be GPL-licensed?]

> I didn't make that claim and have never heard of that claim, and I'm
> not at all sure of the relevance of whatever you're trying to explain
> to the licensing of an overall program, rather than a library.

The point is precisely the one you concede about a project needing to
be licensed compatibly with the GPL, even though to use the combined
work, the result will be GPL-licensed.

[...]

> > All RMS and the FSF's lawyers wanted was that the CNRI licences be GPL-
> > compatible. There are actually various aspects of GPL-compatibility
> > that are beneficial, even if you don't like the copyleft-style
> > clauses, so I don't think it was to the detriment of the Python
> > project.
>
> And I don't have a problem with that.  Honestly I don't.  But as far
> as I'm concerned, although you finally admitted it, a lot of the
> dancing around appeared to be an attempt to disprove my valid
> assertion that a combined work would have to be distributed under the
> GPL, and that no other free software license claims sovereignty over
> the entire work.

I never denied that the GPL would apply to the combined work! Read the
stuff I quote above. Your *own* stuff (for example, the WebKit stuff)
can be licensed compatibly with the GPL (for example, the LGPL), but
the *whole* thing as it lands in the user's lap will be GPL-licensed.

[...]

> > Well, that may not be a judgement shared by the authors. There are
> > numerous tools and components which do dull jobs and whose maintenance
> > is tedious and generally unrewarding, but that doesn't mean that such
> > investment is worth nothing in the face of someone else's so-very-
> > topical high-profile project.
>
> OK, so what you're saying is that readline is so dull and unrewarding
> that the only reason to bother writing it is to reel people in to the
> GPL?

No, what I am saying is that a fair amount of work might have gone
into making readline, even though it may not be shi

Re: open(False) in python3

2010-05-12 Thread Kushal Kumaran
On Wed, May 12, 2010 at 10:56 PM, Giampaolo Rodolà  wrote:
> 2010/5/12 Gabriel Genellina :
>> open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
>> builtin open() + os.fdopen() from 2.x all merged together. It does different
>> things depending on the type and quantity of its arguments, and even returns
>> objects of different types.
>>
>> In particular, open(some_integer) assumes some_integer is a file descriptor
>> and return some variant of file object using the given file descriptor.
>
> Interesting. I wasn't aware of this.
> Is it documented somewhere?
>

http://docs.python.org/py3k/library/functions.html#open

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


How to test whether bit is set within a flag with Python ?

2010-05-12 Thread robert somerville
I am trying to determine how to test whether variors bits are set within a
byte (or larger flag) , the python 'and' and 'or' do not seem to be doing
what i want .. does anybody have some sample code showing how to do it ??

e.g. (in "C")

unsigned char a = 6;

is 3rd bit set ??

a & 4 =,  true in this case 

thanks
Robert Somerville
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to? epydoc --top=README

2010-05-12 Thread Phlip
On May 10, 1:29 pm, Phlip  wrote:
> Pythonistas:
>
> I have a question to epydoc-devel, but it might be languishing:
>
> http://sourceforge.net/mailarchive/forum.php?thread_name=l2n860c114f1...
>
> How do you populate the index.html output with your (insanely clever)
> contents of your README file?
>
> When I try the obvious notations, such as --top=README or --
> top=README.html, I get:
>
> Warning: Identifier 'README' looks suspicious; using it anyway.
> Warning: Could not find top page 'README'; using module-tree.html
> instead
>
> And, yes, the README is included in the input list, and yes I get a
> script-README-module.html
>
> 8<--
>
> The question for the rest of Python-Land: Should I be using a better
> documentation extractor? (pydoc is too mundane so far.) Or should I be
> using a better forum for epydoc users questions?

Regardless of the advocacy, does anyone have an actual answer for
this?

>
> --
>   yes-I-know-topicality-ly-yrs
>   Phlip
>  http://c2.com/cgi/wiki?ZeekLand

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


Re: open(False) in python3

2010-05-12 Thread Terry Reedy

On 5/12/2010 1:26 PM, Giampaolo Rodolà wrote:

2010/5/12 Gabriel Genellina:

open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
builtin open() + os.fdopen() from 2.x all merged together. It does different
things depending on the type and quantity of its arguments, and even returns
objects of different types.


The change actually happened, according to 'What's new', in 2.6 when 
'open' was made a synonym for the new io.open.



In particular, open(some_integer) assumes some_integer is a file descriptor
and return some variant of file object using the given file descriptor.


Interesting. I wasn't aware of this.
Is it documented somewhere?


Right where it should be, in the entry for 'open' under 'built-in 
functions': "file is either ... or an integer file descriptor of the 
file to be wrapped"



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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 12:17 pm, Paul Boddie  wrote:
> On 12 Mai, 16:45, Patrick Maupin  wrote:
>
> > On May 12, 7:43 am, Paul Boddie  wrote:
> > > Thus, "owned my soul" joins "holy war" and "Bin Laden" on the list.
> > > That rhetorical toolbox is looking pretty empty at this point.
>
> > Not emptier than you analogy toolbox.  This is really a pretty stupid
> > analogy, but I guess my lame attempts at showing that are wasted.
>
> Yes they are. The analogy was to point out that someone can really
> want something, but if they are not prepared to accept the "price" of
> acquiring it, then there is no point in them whining about someone
> withholding that thing from them, or whining about someone "forcing"
> them to do stuff, especially when there is clearly no "force" involved
> at all.

But nobody's whining about the strings attached to the software.  Just
pointing out why they sometimes won't use a particular piece of
software, and pointing out that some other people (e.g. random Ubuntu
users) might not understand the full cost of the software, and that
that is because the cost of the software has been deliberately
obscured by using unqualified terms like all-caps "Free Software."

> > > He isn't, though. He's telling you that you can't force other people
> > > to lick the chocolate off whatever "Reese's Peanut Butter cups" are,
> > > rather than actually eating the combination of the two, when you offer
> > > such a combination to someone else.
>
> > No.  That's not what is happening, and you've now officially stretched
> > the analogy way past the breaking point.  In any case, he's telling me
> > I have to give the recipe for my homemade peanut butter.
>
> If you want to redefine the basis of the analogy, then you can talk
> about the recipe all you like, yes. Otherwise, no: the analogy was
> only about people whining about not being able to get stuff with no
> strings attached. I could swap that analogy with one that has someone
> really wanting a ride on a bus, or wanting to go to the moon, where
> they don't like it when someone tells them that they can't get do that
> stuff without agreeing to something or other first. Feel free to start
> discussing the shape of the bus ticket or who pays for spacesuits if
> you want, but to say, "I really want to use that thing, but that nasty
> man has licensed it under the GPL" is whining in precisely the same
> way as featured in the analogy.

Oh, no wonder I didn't understand what you were getting at with the
analogy.  I'm not whining about people licensing stuff under the GPL,
just about its apologists pretending there are never any negative
consequences from it.

> > > Is the Creative Commons share-
> > > alike clause just as objectionable to you, because it's that principle
> > > we're talking about here?
>
> > I have explained that, in some cases, I will use GPL software, and in
> > other cases I won't, and tried to explain why and what the difference
> > is.  Anybody can re-read my posts and figure out that the same might
> > apply to the various Creative Commons licenses.
>
> So it is objectionable to you as well, then.

I somehow knew that is how you would read my posts, but no.  It's
people like you putting words in my month that is objectionable.

> [...]
>
> > > Yes, he's making everyone commit to sharing, and yes, it's like a
> > > snowball effect once people agree to join in.
>
> > Sorry, I sometimes have a hard time distinguishing the semantic
> > difference between "make" and "force".  Could you elucidate?
>
> Yes: once they've agreed to join in, they "have to" go along with the
> whole scheme.

Sorry, that is absolutely no different than what I originally said
when I was first defending Aahz's use of the word "force" to Ben
Finney back on the 7th:

"Perhaps you feel "forces" is too loaded of a word.  There is no
question, however, that a copyright license can require that if you do
"X" with some code, you must also do "Y".  There is also no question
that the GPL uses this capability in copyright law to require anybody
who distributes a derivative work to provide the source.  Thus,
"forced to contribute back any changes" is definitely what happens
once the decision is made to distribute said changes in object form."

Both your "make" and my "force" mean "to compel."  We've come full
circle.  The English language makes no real distinction between
"making everyone commit" and "forcing everyone [to] commit".


> > > But unless you hide that
> > > commitment, no-one imposes anything on anyone. They can get their
> > > chocolate elsewhere. They join in; they are not conscripted.
>
> > And I've already explained why, in some cases, someone might refuse
> > the tastiest chocolate in the world to not join in.
>
> Well, great for them. I thought they were "forced" to join in. I guess
> not.

That's because you use selective quoting of "forced" and deliberately
ignore the context it was used in.

> > No, but copyright licenses are funny things, not like contracts wher

Re: open(False) in python3

2010-05-12 Thread Dave Angel



Giampaolo Rodolà wrote:

2010/5/12 Gabriel Genellina :
  

open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
builtin open() + os.fdopen() from 2.x all merged together. It does different
things depending on the type and quantity of its arguments, and even returns
objects of different types.

In particular, open(some_integer) assumes some_integer is a file descriptor
and return some variant of file object using the given file descriptor.



Interesting. I wasn't aware of this.
Is it documented somewhere?


  

http://docs.python.org/py3k/library/functions.html#open

   or an integer file descriptor of the file to be wrapped.


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


Re: How to test whether bit is set within a flag with Python ?

2010-05-12 Thread MRAB

robert somerville wrote:
I am trying to determine how to test whether variors bits are set within 
a byte (or larger flag) , the python 'and' and 'or' do not seem to be 
doing what i want .. does anybody have some sample code showing how to 
do it ??


e.g. (in "C")

unsigned char a = 6;

is 3rd bit set ??

a & 4 =,  true in this case 


'and', 'or' and 'not' are Boolean.

Python borrows its bitwise operators from C:

& bitwise and
| bitwise or
^ bitwise xor
~ bitwise not (ones' complement)
<>shift right

You also need to remember that Python's integers are of (virtually)
unlimited length.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Stef Mientki
On 12-05-2010 19:42, Joel Koltner wrote:
> Just curious... in Microsoft's Visual Studio (and I would presume some
> other tools), for many languages (both interpreted and compiled!)
> there's an "edit and conitnue" option that, when you hit a breakpoint,
> allows you to modify a line of code before it's actually executed.
>
> Does any Python debugger support this feature?  Being an interpreted
> language it doesn't seem like it would necessarily be too onerous to
> support?  It'd be quite handy in that, especially if you hit a
> breakpoint due to the interpreter throwing an error, you could fix
> just the line in question and keep going, rather than having to stop
> the entire program, fix the line, and then run again and potentially
> kill a bunch of time getting the program back into the same "state."
>
> Thanks,
> ---Joel Koltner
>
winpdb perhaps ?

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


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Terry Reedy

On 5/12/2010 1:42 PM, Joel Koltner wrote:

Just curious... in Microsoft's Visual Studio (and I would presume some
other tools), for many languages (both interpreted and compiled!)
there's an "edit and conitnue" option that, when you hit a breakpoint,
allows you to modify a line of code before it's actually executed.

Does any Python debugger support this feature? Being an interpreted
language it doesn't seem like it would necessarily be too onerous to
support? It'd be quite handy in that, especially if you hit a breakpoint
due to the interpreter throwing an error, you could fix just the line in


CPython compiles Python code (a sequence of statements) to its private 
bytecode (a sequence of codes and operands) and then interprets the 
bytecode. So 'edit and continue' would have to recompile the statement 
and patch the result into the bytecode. Since function compilation 
depends on global analysis of the function, functions would have to be 
recompiled as a whole.


Another problem is recovery of state. If an exception is raised in the 
middle of a statememt, there would need to be a means to roll back the 
state of objects and namespaces to what they were before execution of 
the statement started. So the interpreter would need to act like a 
transactional database, which is not trivial. This would also slow 
normal execution, so it would have to be optional.



question and keep going, rather than having to stop the entire program,
fix the line, and then run again and potentially kill a bunch of time
getting the program back into the same "state."


If would definitely be nice. Perhaps $500,000 in funding would do the trick.

Terry Jan Reedy

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


Re: Limitation of os.walk

2010-05-12 Thread kj
In  Tim Chase writes:
>  05/11/2010 09:07 PM, Terry Reedy wrote:
>> If os.walk were rewritten, it should be as an iterator (generator).
>> Directory entry and exit functions could still be added as params.

>It *is* an iterator/generator.  However, I suspect you mean that 
>it should slurp the dirs/files iteratively instead of using 
>listdir() as was discussed on c.l.p a few months back.

Thanks for mentioning this thread.  Very interesting stuff.  Apropos
the implementability of an iterative listdir, I wonder if some
variation of glob.iglob() would fit the bill.  (Maybe it's too
slow, though.)

>I suspect if I thought about it much longer, only one would 
>really be needed, the other accommodated by the "topdown" parameter.

Yeah, I think one only needs a post hook.  The fact that it's a
generator obviates need for a pre hook, since the yield returns
control to the calling function right around where the pre-hook
would run anyway.  For the same reason, the post hook is needed
only for the case topdown=True.

Another useful callback would be one that replaced listdir in the
generation of the current directory's contents.

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


Re: Picking a license

2010-05-12 Thread Lie Ryan
On 05/13/10 00:53, Patrick Maupin wrote:
> On May 12, 2:19 am, Lie Ryan  wrote:
>> On 05/12/10 06:50, Patrick Maupin wrote:
>>
>>
>>
>>> On May 11, 5:34 am, Paul Boddie  wrote:
 On 10 Mai, 20:36, Patrick Maupin  wrote:
>  The fact is, I know the man would force me to pay for the chocolate, so 
> in
> some cases that enters into the equation and keeps me from wanting the
> chocolate.
>>
 If the man said, "please take the chocolate, but I want you to share
 it with your friends", and you refused to do so because you couldn't
 accept that condition, would it be right to say, "that man is forcing
 me to share chocolate with my friends"?
>>
>>> But the thing is, he's *not* making me share the chocolate with any of
>>> my friends.  He's not even making me share my special peanut butter
>>> and chocolate.  What he's making me do is, if I give my peanut butter
>>> and chocolate to one of my friends, he's making me make *that* friend
>>> promise to share.  I try not to impose obligations like that on my
>>> friends, so obviously the "nice" man with the chocolate isn't my
>>> friend!
>>
>> The analogy breaks here; unlike chocolate, the value of software/source
>> code, if shared, doesn't decrease (in fact, many software increases its
>> value when shared liberally, e.g. p2p apps).
> 
> Absolutely true. Actually, the analogy was really pretty broken to
> start with.  It wasn't my analogy -- I was just trying to play
> along :-)

All analogy is broken, except if the analogy is the exact situation; but
then again, if the analogy is the exact situation, then it's not an
analogy :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Joel Koltner
"Terry Reedy"  wrote in message 
news:[email protected]...
CPython compiles Python code (a sequence of statements) to its private 
bytecode (a sequence of codes and operands) and then interprets the 
bytecode. So 'edit and continue' would have to recompile the statement and 
patch the result into the bytecode.


I believe this is what, e.g., Visual Studio does with, e.g., C++ code -- it 
compiles the modified code and then patches the binary to call the new code as 
a subroutine or somesuch.


Another problem is recovery of state. If an exception is raised in the 
middle of a statememt, there would need to be a means to roll back the state 
of objects and namespaces to what they were before execution of the 
statement started. So the interpreter would need to act like a transactional 
database, which is not trivial.


Yeah, I can see this being challenging.  I think it's pretty cool how some 
Python debuggers will allow you to use a shell with the context set to the 
current function or any of the calling functions higher up the call stack 
hierarchy as well.



This would also slow normal execution, so it would have to be optional.


That'd be a small price to pay. :-)  (Visual Studio only lets you do this with 
unoptimized code...)



If would definitely be nice. Perhaps $500,000 in funding would do the trick.


Cool, if I win the lottery and add it to the "worty causes" list! :-)

Thanks for the information,
---Joel

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


Re: How to test whether bit is set within a flag with Python ?

2010-05-12 Thread cjw

On 12-May-10 14:40 PM, MRAB wrote:

robert somerville wrote:

I am trying to determine how to test whether variors bits are set
within a byte (or larger flag) , the python 'and' and 'or' do not seem
to be doing what i want .. does anybody have some sample code showing
how to do it ??

e.g. (in "C")

unsigned char a = 6;

is 3rd bit set ??

a & 4 =, true in this case 


'and', 'or' and 'not' are Boolean.

Python borrows its bitwise operators from C:

& bitwise and
| bitwise or
^ bitwise xor
~ bitwise not (ones' complement)
<< shift left
 >> shift right

You also need to remember that Python's integers are of (virtually)
unlimited length.


a= 6
if a & 2:
  print 'hit'
else:
  print 'miss'

This hits.

Colin W.

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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 1:00 pm, Paul Boddie  wrote:
> On 12 Mai, 16:10, Patrick Maupin  wrote:
>
> > On May 12, 7:10 am, Paul Boddie  wrote:
> > > What the licence asks you to do and what the author of the licence
> > > wants you to do are two separate things.
>
> > But the whole context was about what RMS wanted me to do and you
> > disagreed!
>
> What RMS as an activist wants is that everyone releases GPL-licensed
> code, except where permissively licensed code might encourage open
> standards proliferation. What RMS the licence author requests is that
> your work is licensed in a way which is compatible with the GPL.

Sorry, didn't know they were twins.

>
> [...]
>
> > > I wrote "the software" above when I meant "your software", but I have
> > > not pretended that the whole system need not be available under the
> > > GPL.
>
> > You say you "have not pretended" but you've never mentioned that it
> > would or even acknowledged the correctness of my assertions about this
> > until now, just claiming that what I said was false.
>
> Well, excuse me! I think we both know that combining something with a
> GPL-licensed work and redistributing it means that the "four freedoms"
> must apply, and that recipients get the work under the GPL. You can
> insist that I said something else, but I spell it out in this post:
>
> http://groups.google.com/group/comp.lang.python/msg/034fbc8289a4d555
>
> Specifically the part...
>
> "Not least because people are only obliged to make their work
> available under a GPL-compatible licence so that people who are using
> the combined work may redistribute it under
> the GPL."
>
> In case you don't find this satisfactory, "their work" means "their
> own work".

OK, but in the last several threads on this sub-part, you kept
contradicting me for some supposed technicality (how was I to know
there were two RMS's?) when I was trying to make the same point.

>
> [...]
>
> > > More loaded terms to replace the last set, I see.
>
> > IMO "Bullying" is the correct term for some of Stallman's actions,
> > including in the clisp debacle.  I knew you wouldn't agree -- that's
> > why YMMV.  And I'm not "replacing" any set of terms -- part of the
> > "bullying" is the "forcing."
>
> Stallman gave Haible the choice to not use readline. Maybe that wasn't
> very nice,

It wasn't even legally correct.  At that point, Stallman had access to
counsel, etc. and should have known better.

> and maybe Haible didn't believe that using readline would
> incur any consequences,

He wasn't distributing it!  It didn't incur any legal consequences;
only the consequence due to not realizing that using readline placed
him squarely inside RMS's chess game.

> but that's what you get when you use a
> copyrighted work.

No.  That's what you get when you use a copyrighted work authored by
an idealist who is trying to spread his choice of license.

> Your language is all about portraying the FSF as
> operating in some kind of illegal or unethical way.

Sorry, didn't mean to be that subtle.  RMS and others at the FSF have,
on multiple occasions, made statements about how licenses work which
are legally false.  This is not illegal, but it is, in my opinion,
unethical.  Some of these claims appear to not be made so boldly any
more, so perhaps they are catching on that others have caught on.

> I guess you
> believe that if you throw enough mud, some of it will stick.

I don't care about mud or sticking.  I am happy to see that the
current wording of the FAQ probably means that another clisp/readline
scenario won't happen, and like to believe that the public outcry over
this sort of thing, and reminders of it in this sort of discussion,
help to remind the FSF that others are watching them.

> > > Again, what I meant was "your software", not the whole software
> > > system. As I more or less state below...
>
> > BUT THAT DOESN'T MATTER.  Once the whole package is licensed under the
> > GPL, for someone downstream to try to scrape the GPL off and get to
> > just the underlying non-GPL parts is harder than scraping bubblegum
> > off your shoe on a hot Texas day.
>
> Big deal. If a project wants to avoid even looking at GPL-licensed
> code for the reason that someone might end up getting the code under
> the GPL, and that they're so bothered that the opportunity to not
> grant such recipients the privileges of modification and
> redistribution disappears because of the GPL, then that's their
> problem.

Yes, I understand it's no big deal to you.  However, what you have
said is not quite right.  If I license something under the MIT
license, I cannot guarantee that no one will ever get it under the
GPL, because it could be redistributed downstream under the GPL (but
then I don't care to in any case).  However, I *can* guarantee that
the code I write (and all the underlying code it relies on) will
remain freely available from me for people who need the ability to,
for example, link with proprietary code.

Despite this not being a very big d

Re: Limitation of os.walk

2010-05-12 Thread kj
In  Terry Reedy 
 writes:

>On 5/11/2010 3:49 PM, kj wrote:
>> PS: I never understood why os.walk does not support hooks for key
>> events during such a tree traversal.

>Either 1) it is intentionally simple, with the expectation that people 
>would write there own code for more complicated uses or 2) no one has 
>submitted a 'full-featured' version or 3) both.

I hope it's not (1): I want the language I use to include more
"batteries" not fewer.

It seems that a similar "simplicity argument" was invoked
to strip the cmp option from sort in Python 3.  G.  Simplicity
is great, but when the drive for it starts causing useful functionality
to be thrown out, then it is going too far.  Yes, I know that it
is possible to do everything that sort's cmp option does through
clever tricks with key, but grokking and coding this maneuver
requires a *lot* more Python-fu than cmp did, which makes this
functionality a lot less accessible to beginners that the intrinsic
complexity of the problem warrants.  And for what?  To get rid of
an *option* that could be easily disregarded by anyone who found
it too "complex"? It makes no sense to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Lie Ryan
On 05/13/10 03:42, Joel Koltner wrote:
> Just curious... in Microsoft's Visual Studio (and I would presume some
> other tools), for many languages (both interpreted and compiled!)
> there's an "edit and conitnue" option that, when you hit a breakpoint,
> allows you to modify a line of code before it's actually executed.
> 
> Does any Python debugger support this feature?  Being an interpreted
> language it doesn't seem like it would necessarily be too onerous to
> support?  It'd be quite handy in that, especially if you hit a
> breakpoint due to the interpreter throwing an error, you could fix just
> the line in question and keep going, rather than having to stop the
> entire program, fix the line, and then run again and potentially kill a
> bunch of time getting the program back into the same "state."
> 

Using pdb, if you step through a function, you can execute arbitrary
python function in the break and then 'jump' to the line after the next,
effectively simulating "edit and continue". I don't know if there's any
GUI interface to pdb that uses them though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Queue.Queue() AttributeError exception

2010-05-12 Thread 钟炳勇
I have a multi-thread program work with Queue.Queue(), sometimes put request to 
the work queue, but throw an exception as below traceback information, it will 
always throw the exception until restart program, cound please have any 
experience, your help will be greatly appreciated!

  File "/usr/local/lib/python2.4/Queue.py", line 71, in put
self.not_full.acquire()
AttributeError: '_Condition' object has no attribute 'acquire'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-12 Thread Ed Keith
--- On Mon, 5/10/10, Ben Finney  wrote:

> So I object to muddying the issue by misrepresenting the
> source of that
> force. Whatever force there is in copyright comes from law,
> not any free
> software license.


You are the one muddying the waters. It does not mater whether you break my 
kneecaps, or hire someone else to break my kneecaps, either way my kneecaps are 
broken. 

You can use any license you want, but the simple fact is that if there are 
fewer restrictions in the license then the user has more freedom in how he uses 
the licensed code. If there are more restrictions he/she has less freedom in 
how he/she uses the licensed code. We can debate which is better (whether a man 
should be free to sell himself into slavery) but to claim that putting more 
restrictions on someone give them more freedom is pure Orwellian double speak. 

Sophistry is the last resort of those who have run out of good arguments. The 
more you engage in it the weaker you make your position.

This thread is generating more heat than light, and probably should be dropped.

   -EdK

Ed Keith
[email protected]

Blog: edkeith.blogspot.com





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


Re: plot debugging problem

2010-05-12 Thread Matteo Landi
On Tue, May 11, 2010 at 8:59 PM, Sandy Sandy  wrote:
>
> 1
>
> remember to include the list,
>
> what does it mean??

I mean that you are leaving out the mlist from your answers. Instead
of press _reply_, look for a _reply-to-all_ button.

>
> 2
>
> do you mean
>
> Pseudo Color Plots
>
> in
>
> http://www.scipy.org/Cookbook/Matplotlib
>
> ??
>
> 3
>
> could you pls clarify what to see in
>
> http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/
>
>
> http://www.scipy.org/Cookbook/Matplotlib
>

As I stated in the previous email, I have no experience with
matplotlib, but in the first link I posted there is an example on how
to integrate matplotlib within a wxpython application. You can start
from it, and look how to attach plot within a gui mailoop.

> S
>
> Well, I cannot tell you how to do that in a precise way, but googling
> a bit I found this (expecially the second example):
>
> http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/
>
> Take a look also at the Matplotlib cookbook:
>
> http://www.scipy.org/Cookbook/Matplotlib
>
> ps. when you answer back, remember to include the list, or the flow will be
> cut!
>
> On Tue, May 11, 2010 at 7:49 PM, Sandy Sandy  wrote:
>> great!!!
>> how to do it?
>>
>> this way it is not working:
>>
>> from pylab import plot,show,close
>> x = range(10)
>> plot(x)
>> from threading import Timer
>> t = Timer(0, show)
>> t.start()
>>
>> y = [2, 8, 3, 9, 4]
>> plot(y)
>> close()
>>
>> Best Regards
>> Sandy
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> From: [email protected]
>>> Date: Tue, 11 May 2010 19:46:27 +0200
>>> Subject: Re: plot debugging problem
>>> To: [email protected]
>>> CC: [email protected]
>>>
>>> I imagine you have to create a separate thread for it. Just thoughts.
>>>
>>> On Tue, May 11, 2010 at 6:08 PM, Sandy Sandy  wrote:
>>> > Hi friends
>>> > pls help with debugging problem
>>> > the mutter is:
>>> > during debugging the  debug processes stacks when fig is created
>>> > for example, in code
>>> >
>>> > import random
>>> >
>>> > import matplotlib.pyplot as plt
>>> > from pylab import *
>>> >
>>> >
>>> > x= 23;
>>> > y = 11;
>>> > print(23456)
>>> > plt.plot(range(10))
>>> >
>>> > plot([1,2,3])
>>> > show()
>>> >
>>> > print()
>>> >
>>> > a=888
>>> >
>>> > it is impossible after show() to continue debug
>>> > as stated in
>>> > Beginning Python Visualization - Crafting Visual Transformation Scripts
>>> > (2009)
>>> > page  187
>>> >
>>> > Note If you’re not using matplotlib interactively in Python, be sure
>>> > to call the function show() after all
>>> > graphs have been generated, as it enters a user interface main loop
>>> > that will stop execution of the rest of
>>> > your code. The reason behind this behavior is that matplotlib is
>>> > designed to be embedded in a GUI as well.
>>> > In Windows, if you’re working from interactive Python, you need only
>>> > issue show() once; close the figures
>>> > (or figures) to return to the shell. Subsequent plots will be drawn
>>> > automatically without issuing show(), and
>>> > you’ll be able to plot graphs interactively.
>>> >
>>> > Best Regards
>>> > Sandy
>>> > 
>>> > Hotmail: Free, trusted and rich email service. Get it now.
>>> > --
>>> > http://mail.python.org/mailman/listinfo/python-list
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Matteo Landi
>>> http://www.matteolandi.net/
>>
>> 
>> Hotmail: Powerful Free email with security by Microsoft. Get it now.
>
>
>
> --
> Matteo Landi
> http://www.matteolandi.net/
>
>
>> From: [email protected]
>> Date: Tue, 11 May 2010 20:37:39 +0200
>> Subject: Re: plot debugging problem
>> To: [email protected]
>> CC: [email protected]
>>
>> Well, I cannot tell you how to do that in a precise way, but googling
>> a bit I found this (expecially the second example):
>>
>> http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/
>>
>> Take a look also at the Matplotlib cookbook:
>>
>> http://www.scipy.org/Cookbook/Matplotlib
>>
>> ps. when you answer back, remember to include the list, or the flow will
>> be cut!
>>
>> On Tue, May 11, 2010 at 7:49 PM, Sandy Sandy  wrote:
>> > great!!!
>> > how to do it?
>> >
>> > this way it is not working:
>> >
>> > from pylab import plot,show,close
>> > x = range(10)
>> > plot(x)
>> > from threading import Timer
>> > t = Timer(0, show)
>> > t.start()
>> >
>> > y = [2, 8, 3, 9, 4]
>> > plot(y)
>> > close()
>> >
>> > Best Regards
>> > Sandy
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >> From: [email protected]
>> >> Date: Tue, 11 May 2010 19:46:27 +0200
>> >> Subject: Re: plot debugging problem
>> >> To: [email protected]
>> >> CC: [email protected]
>> >>
>> >> I imagine you have to create a separate thread for it. Just thoughts.
>> >>
>> >> On Tue, May 11, 2010 at 6:08 PM, Sandy Sandy  wrote:
>> >> > Hi friends
>> >> > pls help with debugging problem
>> >> > the mutter is:
>> >> > during debuggin

python list digest

2010-05-12 Thread Biyana, D. (Dugmore)
Hi All!

I have a huge file and I want to extract subtext starting with "{1:" and
ending with "-}" inclusive. This subtext recurs in many places in the
file and I want the resultant to be in some output file. Any suggestions
about the best way forward. 



Nedbank Limited Reg No 1951/09/06. The following link displays
the names of the Nedbank Board of Directors and Company Secretary.
[ http://www.nedbank.co.za/terms/DirectorsNedbank.htm ]
This email is confidential and is intended for the addressee only.
The following link will take you to Nedbank's legal notice.
[ http://www.nedbank.co.za/terms/EmailDisclaimer.htm ]

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


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Phlip
On May 12, 10:42 am, "Joel Koltner" 
wrote:

> Does any Python debugger support this feature?

I have worked for >3 years by now in Python and have never once
debugged.

People who need "edit and continue" probably need developer tests
instead. You typically edit the test a little, run all the code, edit
the code a little, run all the code, and integrate whenever the code's
a little better and all the tests pass.

To avoid debugging, if the tests fail unexpectedly or mysteriously,
you just 'git reset --hard HEAD'. Your bug disappears. Better than a
debugger!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Joel Koltner
"Phlip"  wrote in message 
news:d580dece-bd42-4753-a0c6-783ce69b5...@m31g2000pre.googlegroups.com...

People who need "edit and continue" probably need developer tests
instead. You typically edit the test a little, run all the code, edit
the code a little, run all the code, and integrate whenever the code's
a little better and all the tests pass.


I find myself making mistakes in typing the name of classes and/or methods 
when I'm first getting started with them (there are some thousands of them 
after all, and even of commonly used classes/methods you're probably talking 
upwards of a hundred), *particularly* when using libraries such as wxWidgets 
that use "fancy" imports that aren't correctly picked up by the "code 
intelligence" analyzers in, e.g., Komodo or Wing.


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


Re: open(False) in python3

2010-05-12 Thread Martin v. Loewis
geremy condra wrote:
> On Wed, May 12, 2010 at 1:36 AM, Stefan Behnel  wrote:
>> Johan Förberg, 12.05.2010 10:05:
>>> On Tue, 11 May 2010 19:27:37 -0300, Gabriel Genellina wrote:
>>>
 so open(False) is the same as open(0), and 0 is the file descriptor
 associated to standard input. The program isn't hung, it's just waiting
 for you to type some text
>>> That's interesting. Are there any more numbered pseudofiles? I suppose
>>> its mainly an excellent way to confuse people when you open(0).read(),
>>> but it would be interesting to know.
>> Standard Unix behaviour dictates that 0 is stdin, 1 is stdout, and 2 is
>> stderr. So you can only read() from 0.
>>
>> Stefan
> 
> Nitpicking, but open(1).read() and open(2).read() both succeed
> (for small values of success) the same way that open(0).read()
> does.

That's because your operating system made that so. Try a different
operating system, and you may get different results.

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


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Phlip
On May 12, 12:44 pm, "Joel Koltner" 
wrote:

> I find myself making mistakes in typing the name of classes and/or methods
> when I'm first getting started with them (there are some thousands of them
> after all, and even of commonly used classes/methods you're probably talking
> upwards of a hundred), *particularly* when using libraries such as wxWidgets
> that use "fancy" imports that aren't correctly picked up by the "code
> intelligence" analyzers in, e.g., Komodo or Wing.

Are you implying that you then run the code, and - after a handful of
higher-level calls - control flow gets down to the lines you just
typed, and the run fails because they are misspelled? The only fix is
decoupling, and _expecting_ your first few debugger or test runs to
fail.

Other than that, lolwut?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Joel Koltner
"Phlip"  wrote in message 
news:75c050d2-365e-4b08-8716-884ed5473...@k25g2000prh.googlegroups.com...

On May 12, 12:44 pm, "Joel Koltner" 
wrote:

Are you implying that you then run the code, and - after a handful of
higher-level calls - control flow gets down to the lines you just
typed, and the run fails because they are misspelled?


Correct.


The only fix is
decoupling, and _expecting_ your first few debugger or test runs to
fail.


Well, sure, that is the current fix... but an "edit and continue" feature 
would make for a much faster fix. :-)


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


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Phlip
On May 12, 1:38 pm, "Joel Koltner" 
wrote:

> Well, sure, that is the current fix... but an "edit and continue" feature
> would make for a much faster fix. :-)

Are you implying, after an edit, you need to start a program again,
then enter several user inputs, to navigate back to the place where
you hit the syntax error? (WxWidgets noted - props!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread John Nagle

Joel Koltner wrote:
Just curious... in Microsoft's Visual Studio (and I would presume some 
other tools), for many languages (both interpreted and compiled!) 
there's an "edit and conitnue" option that, when you hit a breakpoint, 
allows you to modify a line of code before it's actually executed.


Does any Python debugger support this feature?  Being an interpreted 
language it doesn't seem like it would necessarily be too onerous to 
support?  It'd be quite handy in that, especially if you hit a 
breakpoint due to the interpreter throwing an error, you could fix just 
the line in question and keep going, rather than having to stop the 
entire program, fix the line, and then run again and potentially kill a 
bunch of time getting the program back into the same "state."


   Having actually used LISP systems with "edit and continue", it's a good
thing that Python doesn't have it.  It encourages a "patch" mentality, and
the resulting code is usually disappointing.

   What the original poster seems to need is a global analysis
tool that insures that all names used are defined.  Like "pylint".

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


RE: Do any debuggers support "edit and continue?"

2010-05-12 Thread Sandy Sandy


maybe ipython?


http://showmedo.com/videos/video?name=120&fromSeriesID=100



> From: [email protected]
> Subject: Do any debuggers support "edit and continue?"
> Date: Wed, 12 May 2010 10:42:31 -0700
> To: [email protected]
> 
> Just curious... in Microsoft's Visual Studio (and I would presume some other 
> tools), for many languages (both interpreted and compiled!) there's an "edit 
> and conitnue" option that, when you hit a breakpoint, allows you to modify a 
> line of code before it's actually executed.
> 
> Does any Python debugger support this feature?  Being an interpreted language 
> it doesn't seem like it would necessarily be too onerous to support?  It'd be 
> quite handy in that, especially if you hit a breakpoint due to the 
> interpreter 
> throwing an error, you could fix just the line in question and keep going, 
> rather than having to stop the entire program, fix the line, and then run 
> again and potentially kill a bunch of time getting the program back into the 
> same "state."
> 
> Thanks,
> ---Joel Koltner
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  
_
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


fails to call python from jython for types, functools, csv modules

2010-05-12 Thread Joax Spec
Hello I'm very new to python/jython, and trying yo *call a program from
jython*, which works very good in python.
I got some issues which resolve as I expose here, but I think these are
unsatisfactory solutions.
If you want to reply please do it to my address.

thanks,
Jx

PD. both are great projects!!!

1. FIRST Error

Error !Traceback (most recent call last):
  File "", line 1, in 
  File "__pyclasspath__/parserJoax.py", line 1, in 
  File "C:\Python26\lib\re.py", line 283, in 
import copy_reg
  File "C:\Python26\lib\copy_reg.py", line 7, in 
from types import ClassType as _ClassType
  File "C:\Python26\lib\types.py", line 36, in 
BufferType = buffer
NameError: name 'buffer' is not defined

*Solution --> comment in types.py   #BufferType = buffer (line 37)*

2. SECOND Error

Error !Traceback (most recent call last):
  File "", line 1, in 
  File "__pyclasspath__/parserJoax.py", line 3, in 
  File "C:\Python26\lib\csv.py", line 7, in 
from functools import reduce
  File "C:\Python26\lib\functools.py", line 10, in 
from _functools import partial, reduce
ImportError: cannot import name reduce

*Solution --> comment in functools.py   #, reduce (line 10)
Problem --> IDLE for windows doesn't work anymore, I mean I can lauch the
GUI, but I can still use python from command line*

3. THIRD Error

Error !Traceback (most recent call last):
  File "", line 1, in 
  File "__pyclasspath__/parserJoax.py", line 3, in 
  File "C:\Python26\lib\csv.py", line 7, in 
from functools import reduce
ImportError: cannot import name reduce

*Solution --> comment in csv.py  #[email protected] (line 96)*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Joel Koltner
"Phlip"  wrote in message 
news:c014ae9f-99d8-4857-a3f7-e6ac16e45...@e34g2000pra.googlegroups.com...

Are you implying, after an edit, you need to start a program again,
then enter several user inputs, to navigate back to the place where
you hit the syntax error? (WxWidgets noted - props!)


Pretty much, yeah... Realistically, we're probably talking less than a minute 
each time, so objectively it's not really a big deal -- it's just different 
than what I'm used to so I'm noticing it more. :-)


I guess what I'm realizing here is that one of the upsides of compiled 
languages is that they'll (usually) catch most typos before your program even 
runs!


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


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Joel Koltner
"John Nagle"  wrote in message 
news:[email protected]...

   Having actually used LISP systems with "edit and continue", it's a good
thing that Python doesn't have it.  It encourages a "patch" mentality, and
the resulting code is usually disappointing.


Hey, a lot of people would argue that Python's lack of strong typing and 
data/member protection (from one class to another) encourages sloppy 
programming too. :-)  (Some people even figure that automatic garbage 
collection does so!)



   What the original poster seems to need is a global analysis
tool that insures that all names used are defined.  Like "pylint".


Sounds intriguing... I'll check it out; thanks!

---Joel

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


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Phlip
On May 12, 3:03 pm, "Joel Koltner" 
wrote:

> Pretty much, yeah... Realistically, we're probably talking less than a minute
> each time, so objectively it's not really a big deal -- it's just different
> than what I'm used to so I'm noticing it more. :-)
>
> I guess what I'm realizing here is that one of the upsides of compiled
> languages is that they'll (usually) catch most typos before your program even
> runs!

When you write developer tests ("unit tests"), you edit the code for a
while, hit a test button, and get instant feedback - syntax errors,
assertion failures, or a green bar. Then you edit a little more. This
allows you to learn to make the smallest possible edits that
constantly return you to a testworthy state.

Each test case does everything you did, manually. It sets up various
inputs and runs them thru a system. Better, it sets up inputs for each
specific method, not just for the whole app. That helps decouple the
specific methods, so they don't accidentally depend on everything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Limitation of os.walk

2010-05-12 Thread Patrick Maupin
On May 12, 2:04 pm, kj  wrote:
> It seems that a similar "simplicity argument" was invoked
> to strip the cmp option from sort in Python 3.  G.  Simplicity
> is great, but when the drive for it starts causing useful functionality
> to be thrown out, then it is going too far.  Yes, I know that it
> is possible to do everything that sort's cmp option does through
> clever tricks with key, but grokking and coding this maneuver
> requires a *lot* more Python-fu than cmp did, which makes this
> functionality a lot less accessible to beginners that the intrinsic
> complexity of the problem warrants.  And for what?  To get rid of
> an *option* that could be easily disregarded by anyone who found
> it too "complex"? It makes no sense to me.

I didn't follow the discussion on cmp and Python 3, but I would assume
one reason it was removed was for performance.  cmp is very slow
compared to key, and if there should be one obvious way to do it, it
should probably be the way that runs faster.  Also, while in many
cases cmp can be easier to use than key, it would be possible for a
naive person with a complicated data structure to come up with a cmp
function that, e.g. sorted A > B, B > C, and C > A.  It's impossible
to come up with a key function that will break sort in that fashion.
So, while I understand the frustration of having a favorite tool
removed, I have no trouble believing that there were good reasons for
the removal.

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


Re: Picking a license

2010-05-12 Thread Paul Boddie
On 12 Mai, 21:02, Patrick Maupin  wrote:
> On May 12, 1:00 pm, Paul Boddie  wrote:

[Quoting himself...]

> > "Not least because people are only obliged to make their work
> > available under a GPL-compatible licence so that people who are using
> > the combined work may redistribute it under
> > the GPL."
>
> > In case you don't find this satisfactory, "their work" means "their
> > own work".
>
> OK, but in the last several threads on this sub-part, you kept
> contradicting me for some supposed technicality (how was I to know
> there were two RMS's?) when I was trying to make the same point.

We both agree that any combining a work with a GPL-licensed work means
that the result has to be distributable under the GPL. I was also
merely pointing out that the non-GPL-licensed work has to be licensed
compatibly if the possibility of combination with GPL-licensed works
exists, but you still get to choose the licence. You even acknowledged
this:

"In practice, what it really means is that the combination (e.g. the
whole program) would effectively be GPL-licensed.  This then means
that downstream users would have to double-check that they are not
combining the whole work with licenses which are GPL-incompatible,
even if they are not using the svg feature."

And for the last time, Stallman's opinion on what you should or should
not do is a distinct matter from the actual use of these licences.

[Haible and readline]

> He wasn't distributing it!  It didn't incur any legal consequences;
> only the consequence due to not realizing that using readline placed
> him squarely inside RMS's chess game.

Really, what Stallman did in 1992 is a matter for Stallman to defend.
Whether a bunch of people use the GPL to license their work or not is
a separate matter. All I can say is that Stallman's reasoning was
probably driven by the possibility that someone could license their
work in a fashion that is incompatible with readline, but deliberately
be able to make use of it technically, and then when a user combines
that work and readline, the user is told that although readline is
used in that combined work, the licensing terms do not now apply.

[...]

> No.  That's what you get when you use a copyrighted work authored by
> an idealist who is trying to spread his choice of license.

Well, take it up with Stallman, then. It's a separate issue from the
use of the FSF's licences and even how the FSF functions today.

[...]

> Yes, I understand it's no big deal to you.  However, what you have
> said is not quite right.  If I license something under the MIT
> license, I cannot guarantee that no one will ever get it under the
> GPL, because it could be redistributed downstream under the GPL (but
> then I don't care to in any case).  However, I *can* guarantee that
> the code I write (and all the underlying code it relies on) will
> remain freely available from me for people who need the ability to,
> for example, link with proprietary code.

Yes, and as I said, in the context of a program landing in a user's
lap, there is no guarantee that such a program will offer users any
privileges other than to run the program, and then maybe only under
certain conditions. Which is how this discussion began.

> Despite this not being a very big deal to you, the whole tempest in a
> teacup here is about this very issue.  Yes, I understand it is a
> problem for me, or any other author who wants to provide code that can
> be used freely by people who download it.  And, as has been pointed
> out in this discussion, many people don't read licenses very
> carefully, so someone who doesn't want to restrict other people from
> linking his library with third party proprietary code should think
> twice about using the GPL.

Sure, the permissive licences declare fewer restrictions or
obligations on immediate recipients, but what kicked this discussion
off was the remark about end-user privileges, not what certain
recipients (but not others) are able to do with the code.

[...]

> > No, what I am saying is that a fair amount of work might have gone
> > into making readline, even though it may not be shiny enough by some
> > people's standards, but that doesn't mean you can disregard the
> > authors' wishes by insisting that is it "trivial" or unimportant,
> > whereas your own software somehow is important. As soon as you go down
> > that road, everyone can start belittling the works of others purely so
> > that they can start disregarding the terms which regulate those works,
> > and then it's a free-for-all.
>
> Ahh, well done.  You've sucked me into a meaningless side debate.  If
> I'm not distributing readline, then legally the license distribution
> terms don't apply to me.  End of story.  (Morally, now we might get
> into how trivial it is or isn't.)

According to the FSF, whose opinions you don't trust, it doesn't
matter if you do distribute readline or not:

http://www.gnu.org/licenses/gpl-faq.html#LinkingWithGPL
http://www.gnu.org/licenses/gpl-faq.

Re: How to test whether bit is set within a flag with Python ?

2010-05-12 Thread Mensanator
On May 12, 1:40 pm, MRAB  wrote:
> robert somerville wrote:
> > I am trying to determine how to test whether variors bits are set within
> > a byte (or larger flag) , the python 'and' and 'or' do not seem to be
> > doing what i want .. does anybody have some sample code showing how to
> > do it ??
>
> > e.g. (in "C")
>
> > unsigned char a = 6;
>
> > is 3rd bit set ??
>
> > a & 4 =,  true in this case 
>
> 'and', 'or' and 'not' are Boolean.
>
> Python borrows its bitwise operators from C:
>
>      &     bitwise and
>      |     bitwise or
>      ^     bitwise xor
>      ~     bitwise not (ones' complement)
>      <<    shift left
>      >>    shift right
>
> You also need to remember that Python's integers are of (virtually)
> unlimited length.

The gmpy module has a wonderful set of functions tailored to the
bit twiddler:

FUNCTIONS
bit_length(...)
bit_length(x): returns length of string representing x in base
2

>>> gmpy.bit_length(275)
9

digits(...)
digits(x[,base]): returns Python string representing x in the
given base (2 to 36, default 10 if omitted or 0); leading '-'
present if x<0, but no leading '+' if x>=0. x must be an mpz,
or else gets coerced into one.

>>> gmpy.digits(275,2)
'100010011'

hamdist(...)
hamdist(x,y): returns the Hamming distance (number of bit-
positions
where the bits differ) between x and y.  x and y must be mpz,
or else
get coerced to mpz.

>>> a = 275# '100010011'
>>> b = 333# '101001101'
   #x 
>>> gmpy.hamdist(a,b)
5

lowbits(...)
lowbits(x,n): returns the n lowest bits of x; n must be an
ordinary Python int, >0; x must be an mpz, or else gets
coerced to one.

>>> gmpy.digits(gmpy.lowbits(333,8),2)
'1001101' # (bit 7 was a 0)

numdigits(...)
numdigits(x[,base]): returns length of string representing x
in
the given base (2 to 36, default 10 if omitted or 0); the
value
returned may sometimes be 1 more than necessary; no provision
for any 'sign' character, nor leading '0' or '0x' decoration,
is made in the returned length.  x must be an mpz, or else
gets
coerced into one.

>>> import collatz_functions
>>> c = collatz_functions.Type12MH(6,1)
>>> gmpy.numdigits(c,2)
177149

popcount(...)
popcount(x): returns the number of 1-bits set in x; note that
this is 'infinite' if x<0, and in that case, -1 is returned.
x must be an mpz, or else gets coerced to one.

>>> gmpy.popcount(3**33)
34
>>> gmpy.digits(3**33,2)
'1001110101010011001011010101110111011'

scan0(...)
scan0(x, n=0): returns the bit-index of the first 0-bit of x
(that
is at least n); n must be an ordinary Python int, >=0.  If no
more
0-bits are in x at or above bit-index n (which can only happen
for
x<0, notionally extended with infinite 1-bits), None is
returned.
x must be an mpz, or else gets coerced to one.

>>> gmpy.scan0(3**33,4) # find first 0 bit starting at bit4
4
'1001110101010011001011010101110111011'
 x
scan1(...)
scan1(x, n=0): returns the bit-index of the first 1-bit of x
(that
is at least n); n must be an ordinary Python int, >=0.  If no
more
1-bits are in x at or above bit-index n (which can only happen
for
x>=0, notionally extended with infinite 0-bits), None is
returned.
x must be an mpz, or else gets coerced to one.

>>> gmpy.scan1(3**33,4) # find first 1 bit starting at bit4
7
'1001110101010011001011010101110111011'
  x

setbit(...)
setbit(x,n,v=1): returns a copy of the value of x, with bit n
set
to value v; n must be an ordinary Python int, >=0; v, 0 or !
=0;
x must be an mpz, or else gets coerced to one.

>>> a = 2**24+1
>>> gmpy.digits(a,2)
'10001'
>>> a = gmpy.setbit(a,12,1)
>>> gmpy.digits(a,2)
'100010001'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open(False) in python3

2010-05-12 Thread Jan Kaliszewski
Terry Reedy dixit (2010-05-12, 14:26):

> On 5/12/2010 1:26 PM, Giampaolo Rodolà wrote:
> >2010/5/12 Gabriel Genellina:
> >>open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
> >>builtin open() + os.fdopen() from 2.x all merged together. It does different
> >>things depending on the type and quantity of its arguments, and even returns
> >>objects of different types.
> 
> The change actually happened, according to 'What's new', in 2.6 when
> 'open' was made a synonym for the new io.open.

It did happened in 3.0, not in 2.6.

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


Re: Picking a license

2010-05-12 Thread Paul Boddie
On 12 Mai, 20:29, Patrick Maupin  wrote:
>
> But nobody's whining about the strings attached to the software.  Just
> pointing out why they sometimes won't use a particular piece of
> software, and pointing out that some other people (e.g. random Ubuntu
> users) might not understand the full cost of the software, and that
> that is because the cost of the software has been deliberately
> obscured by using unqualified terms like all-caps "Free Software."

Right. The "full cost" of software that probably cost them nothing
monetarily and which comes with all the sources, some through a chain
of distribution and improvement which could have led to proprietary
software had the earliest stages in the chain involved permissive
licensing. And that they can't sell a binary-only Ubuntu derivative.

[...]

> Oh, no wonder I didn't understand what you were getting at with the
> analogy.  I'm not whining about people licensing stuff under the GPL,
> just about its apologists pretending there are never any negative
> consequences from it.

So, the "negative consequences" are that people can't make proprietary
editions of some software. When that's a deliberate choice in the
design of a licence, there's no pretending that the consequences
aren't there, just that they aren't perceived by everyone to be
negative.

[Sharing alike]

> I somehow knew that is how you would read my posts, but no.  It's
> people like you putting words in my month that is objectionable.

Well, you effectively said that you didn't like being asked to "share
alike", which is what the GPL achieves, so why should I not assume
that you generally object to other, more obviously labelled licences
like the CC-*-SA licences which make it clear what is expected of that
hapless recipient of a work who doesn't bother reading the licence?

[Obligations after joining a scheme]

> Sorry, that is absolutely no different than what I originally said
> when I was first defending Aahz's use of the word "force" to Ben
> Finney back on the 7th:
>
> "Perhaps you feel "forces" is too loaded of a word.  There is no
> question, however, that a copyright license can require that if you do
> "X" with some code, you must also do "Y".  There is also no question
> that the GPL uses this capability in copyright law to require anybody
> who distributes a derivative work to provide the source.  Thus,
> "forced to contribute back any changes" is definitely what happens
> once the decision is made to distribute said changes in object form."
>
> Both your "make" and my "force" mean "to compel."  We've come full
> circle.  The English language makes no real distinction between
> "making everyone commit" and "forcing everyone [to] commit".

Yes, but you have to choose to do something ("X") to start with. Which
is actually what you wrote later in that exchange:

"Again, the force is applied once you choose to do a particular thing
with the software -- is is really that hard to understand that
concept?"

But you're virtually claiming that people stumble into a situation
where they have to do something they don't like or didn't anticipate,
when in fact they've actually entered into an agreement.

[...]

> My problem, exactly, is that bothering Mepis, yet not bothering Joe
> Blow when he gives a copy to his friend, is exactly the kind of
> selective enforcement of copyright rights that Microsoft is accused of
> when they turn a blind eye to piracy in third-world countries.

Nonsense. If anything, it's a matter of priorities, and completely
absurd to claim that the FSF and all the other copyright holders for
GPL-licensed software on Ubuntu installation media are all conspiring
together to "seed" the planet with "unlicensed wares" in order to reap
some kind of monetary reward afterwards, which is what Microsoft has
been accused of.

[...]

> Despite your opinion, there is nothing legally or morally wrong with
> me using GPL software (and not redistributing it) just because I

I never said there was. I said that if you don't like the licence,
don't incorporate works which use it into your own projects. But don't
say that it's not fair that people are releasing stuff under terms you
don't like, or say that they're being "pathetic" or petty or
ridiculous by doing so, or are imposing their agenda on you.

> happen to feel that (a) for my purposes, for most stuff I write, it
> happens to be the wrong license, (b) (especially historically) some of
> the practices used to insure proliferation of the GPL are ethically
> questionable, and (c) whenever these ethically questionable practices
> are discussed, quasi-religious apologists will take these questionable
> practices to the next level, by selective quoting and bad analogies
> and hinting at things without actually coming out and saying them, and
> all sorts of other debate tactics designed to confuse rather than
> enlighten.

More name-calling and finger-pointing. Great stuff, there. Anything
else?

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

Re: Picking a license

2010-05-12 Thread Paul Boddie
On 11 Mai, 14:12, Ed Keith  wrote:
> --- On Mon, 5/10/10, Ben Finney  wrote:
>
> > So I object to muddying the issue by misrepresenting the source of that
> > force. Whatever force there is in copyright comes from law, not any free
> > software license.
>
> You are the one muddying the waters. It does not mater whether you break my
> kneecaps, or hire someone else to break my kneecaps, either way my kneecaps
> are broken.

Nice analogy. In fact, the "force" mentioned above is nothing more
than the thing which makes these licensing agreements binding. All the
talk about the GPL "forcing" people to do stuff, when the stuff is
actually one side of a bargain or the obligations of a party in an
agreement, is great theatre but nothing more.

> You can use any license you want, but the simple fact is that if there are
> fewer restrictions in the license then the user has more freedom in how he
> uses the licensed code.

Yes, the recipient of that code as issued by you has fewer
restrictions on their actions and thus more privileges. However,
recipients of the extended work may be denied any or nearly all of
these privileges.

> If there are more restrictions he/she has less freedom in how he/she uses
> the licensed code.

Yes, that recipient does not get to exercise certain privileges.
However, recipients of the extended work retain the same set of
privileges. As do recipients of the work upon subsequent
redistribution.

> We can debate which is better (whether a man should be free to sell
> himself into slavery) but to claim that putting more restrictions on
> someone give them more freedom is pure Orwellian double speak.

It may provide fewer privileges for initial recipients but may grant
those privileges more widely.

> Sophistry is the last resort of those who have run out of good
> arguments. The more you engage in it the weaker you make your position.

Then I challenge you to dispute the statements of my last three
paragraphs without introducing a specific notion of "freedom" in order
to make your case.

> This thread is generating more heat than light, and probably should be 
> dropped.

On this I don't necessarily disagree.

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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 5:41 pm, Paul Boddie  wrote:
> > Ahh, well done.  You've sucked me into a meaningless side debate.  If
> > I'm not distributing readline, then legally the license distribution
> > terms don't apply to me.  End of story.  (Morally, now we might get
> > into how trivial it is or isn't.)
>
> According to the FSF, whose opinions you don't trust, it doesn't
> matter if you do distribute readline or not:
>
> http://www.gnu.org/licenses/gpl-faq.html#LinkingWithGPLhttp://www.gnu.org/licenses/gpl-faq.html#IfLibraryIsGPL
>
> From version 3 of the GPL:
>
> "For example, Corresponding Source includes interface definition files
> associated with source files for the work, and the source code for
> shared libraries and dynamically linked subprograms that the work is
> specifically designed to require, such as by intimate data
> communication or control flow between those subprograms and other
> parts of the work."
>
> You may beg to differ. I would advise against doing so in a courtroom.

Well, it's unlikely anybody will get a chance in a courtroom, because
nobody's going to bring suit.

>
> > But you don't need to know anything else.  RMS claimed clisp was a
> > derivative work of readline, even though readline wasn't even
> > distributed with clisp.  That's just plain copyright misuse, and if it
> > had gone to court with good lawyers, RMS might have lost the copyright
> > protections for readline.
>
> Now that *is* a ridiculous statement. Just because a decision is made
> that one work is not derived from another does not mean that the
> claimed original work is no longer subject to copyright.

Well, it won't come to court because the FSF is just going to posture
on this issue, but never really sue anybody (certainly not any open
source project), because they would lose both in court and in public
opinion.  But if they did decide to sue, a few prior cases like Sega v
Accolade and Galoob v Nintendo, as well as the court's use of the
abstraction, filtration and comparison tests to strip functionality
away from copyrightable subject matter, would probably be dispositive
in determining that a substantial program like clisp that didn't
include readline, but which could use readline, is not, in fact, a
derivative of readline.

Once the court reaches that conclusion, it would only be a tiny step
to find that the FSF's attempt to claim that clisp infringes the
readline copyright to be a misuse of that same readline copyright.
See, e.g. LaserComb v Reynolds, where the defendant (IMHO) acted much
more egregiously than anybody who is delivering free software like
clisp is acting, and nevertheless won on that issue.

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


Re: Picking a license

2010-05-12 Thread Patrick Maupin
On May 12, 6:15 pm, Paul Boddie  wrote:
> On 12 Mai, 20:29, Patrick Maupin  wrote:
>
>
>
> > But nobody's whining about the strings attached to the software.  Just
> > pointing out why they sometimes won't use a particular piece of
> > software, and pointing out that some other people (e.g. random Ubuntu
> > users) might not understand the full cost of the software, and that
> > that is because the cost of the software has been deliberately
> > obscured by using unqualified terms like all-caps "Free Software."
>
> Right. The "full cost" of software that probably cost them nothing
> monetarily and which comes with all the sources, some through a chain
> of distribution and improvement which could have led to proprietary
> software had the earliest stages in the chain involved permissive
> licensing. And that they can't sell a binary-only Ubuntu derivative.

Who's talking about selling a binary-only version -- there is a good
chance they can't even give away a binary CD without violating
copyright.

> [...]
>
> > Oh, no wonder I didn't understand what you were getting at with the
> > analogy.  I'm not whining about people licensing stuff under the GPL,
> > just about its apologists pretending there are never any negative
> > consequences from it.
>
> So, the "negative consequences" are that people can't make proprietary
> editions of some software. When that's a deliberate choice in the
> design of a licence, there's no pretending that the consequences
> aren't there, just that they aren't perceived by everyone to be
> negative.

I gave an example earlier of svglib and rst2pdf.  Negative
consequences.  Nothing proprietary involved.

> > I somehow knew that is how you would read my posts, but no.  It's
> > people like you putting words in my month that is objectionable.
>
> Well, you effectively said that you didn't like being asked to "share
> alike", which is what the GPL achieves.

I give away lots of software.  Free to all comers.  Come and get some.

> so why should I not assume
> that you generally object to other, more obviously labelled licences
> like the CC-*-SA licences which make it clear what is expected of that
> hapless recipient of a work who doesn't bother reading the licence?

Your assumptions are so far away from reality that there is really no
good reason why you shouldn't assume that I'm a 10 foot tall purple
monster.

> > Sorry, that is absolutely no different than what I originally said
> > when I was first defending Aahz's use of the word "force" to Ben
> > Finney back on the 7th:
>
> > "Perhaps you feel "forces" is too loaded of a word.  There is no
> > question, however, that a copyright license can require that if you do
> > "X" with some code, you must also do "Y".  There is also no question
> > that the GPL uses this capability in copyright law to require anybody
> > who distributes a derivative work to provide the source.  Thus,
> > "forced to contribute back any changes" is definitely what happens
> > once the decision is made to distribute said changes in object form."
>
> > Both your "make" and my "force" mean "to compel."  We've come full
> > circle.  The English language makes no real distinction between
> > "making everyone commit" and "forcing everyone [to] commit".
>
> Yes, but you have to choose to do something ("X") to start with. Which
> is actually what you wrote later in that exchange:
>
> "Again, the force is applied once you choose to do a particular thing
> with the software -- is is really that hard to understand that
> concept?"

I didn't just write that later.  I wrote it in my very first post,
which you just quoted a few lines up, apparently without even
bothering to read it closely.  I agree with that.  But you only
grudgingly agree with that, if at all, and when you do you make it
look like I'm the one trying desperately not to agree with it, because
in order to agree with it, you have to agree that, in the limited
context that I used the word "force", it is accurate, and you really
don't want to do that.

> But you're virtually claiming that people stumble into a situation
> where they have to do something they don't like or didn't anticipate,
> when in fact they've actually entered into an agreement.

Some people (end users of Ubuntu) do stumble into a situation.  Some
people see and decide not to enter into an agreement and attempt to
warn others that there may be consequences -- that if they enter into
the agreement they will be "forced" to live with those consequences.
This latter group of people always winds up arguing with those who
think the GPL is always good and none of the consequences are ever
negative, and forced is a loaded word.

> > My problem, exactly, is that bothering Mepis, yet not bothering Joe
> > Blow when he gives a copy to his friend, is exactly the kind of
> > selective enforcement of copyright rights that Microsoft is accused of
> > when they turn a blind eye to piracy in third-world countries.
>
> Nonsense. If anything, it's a mat

Re: Is Python a functional programming language?

2010-05-12 Thread Lawrence D'Oliveiro
In message , Nobody wrote:

> On Tue, 11 May 2010 23:13:10 +1200, Lawrence D'Oliveiro wrote:
> 
>>> But the beauty is that Python is multi-paradigm ...
>> 
>> The trouble with “multi-paradigm” is that it offends the zealots on
>> all sides.
> 
> Is that how you view people who like languages to exhibit a degree of
> consistency?

Interesting, I never knew “consistency” was a synonym for “faith”...

> Some people would prefer to have a manageable set of rules
> rather than having to remember the results of all of the possible
> combinations of interactions between language features.

What are you accusing Python of, exactly?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: documentation bug? (format spec mini language)

2010-05-12 Thread Alan G Isaac
On 5/11/2010 5:05 PM, Terry Reedy wrote:  

http://bugs.python.org/issue8691


Thanks!

Alan


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


Re: How to test whether bit is set within a flag with Python ?

2010-05-12 Thread Jess
Cheap Chanel Watches for sale at: http://www.luxuryowner.net/

Chanel Watches collection: 
http://www.luxuryowner.net/replica-chanel-watches.html

Chanel J12 Automatic Watches: 
http://www.luxuryowner.net/Chanel-J12-Automatic-Watches.html

Chanel J12 Quartz Watches: 
http://www.luxuryowner.net/Chanel-J12-Quartz-Watches.html


"MRAB"  
??:[email protected]...
> robert somerville wrote:
>> I am trying to determine how to test whether variors bits are set within 
>> a byte (or larger flag) , the python 'and' and 'or' do not seem to be 
>> doing what i want .. does anybody have some sample code showing how to do 
>> it ??
>>
>> e.g. (in "C")
>>
>> unsigned char a = 6;
>>
>> is 3rd bit set ??
>>
>> a & 4 =,  true in this case 
>>
> 'and', 'or' and 'not' are Boolean.
>
> Python borrows its bitwise operators from C:
>
> & bitwise and
> | bitwise or
> ^ bitwise xor
> ~ bitwise not (ones' complement)
> < >>shift right
>
> You also need to remember that Python's integers are of (virtually)
> unlimited length. 


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


Re: Do any debuggers support "edit and continue?"

2010-05-12 Thread Jess
Cheap Chanel Watches for sale at: http://www.luxuryowner.net/

Chanel Watches collection: 
http://www.luxuryowner.net/replica-chanel-watches.html

Chanel J12 Automatic Watches: 
http://www.luxuryowner.net/Chanel-J12-Automatic-Watches.html

Chanel J12 Quartz Watches: 
http://www.luxuryowner.net/Chanel-J12-Quartz-Watches.html


"Joel Koltner"  
??:[email protected]...
> Just curious... in Microsoft's Visual Studio (and I would presume some 
> other tools), for many languages (both interpreted and compiled!) there's 
> an "edit and conitnue" option that, when you hit a breakpoint, allows you 
> to modify a line of code before it's actually executed.
>
> Does any Python debugger support this feature?  Being an interpreted 
> language it doesn't seem like it would necessarily be too onerous to 
> support?  It'd be quite handy in that, especially if you hit a breakpoint 
> due to the interpreter throwing an error, you could fix just the line in 
> question and keep going, rather than having to stop the entire program, 
> fix the line, and then run again and potentially kill a bunch of time 
> getting the program back into the same "state."
>
> Thanks,
> ---Joel Koltner
> 


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


buffer objects (C-API)

2010-05-12 Thread moerchendiser2k3
Hi at all,

is it possible that a buffer object deallocates the memory when the
object is destroyed? I want to wrap the buffer object around some
memory. Or is there any chance that the buffer object copies the
memory so it will be responsible when it will be destroyed?

Thanks in advance, bye.

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


Re: open(False) in python3

2010-05-12 Thread Terry Reedy

On 5/12/2010 7:07 PM, Jan Kaliszewski wrote:

Terry Reedy dixit (2010-05-12, 14:26):


On 5/12/2010 1:26 PM, Giampaolo Rodolà wrote:

2010/5/12 Gabriel Genellina:

open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
builtin open() + os.fdopen() from 2.x all merged together. It does different
things depending on the type and quantity of its arguments, and even returns
objects of different types.


The change actually happened, according to 'What's new', in 2.6 when
'open' was made a synonym for the new io.open.


It did happened in 3.0, not in 2.6.


I do not have 2.6 loaded to test and was judging from

What's New in Python 3.0 has a section

Changes Already Present In Python 2.6 which has an entry

"PEP 3116: New I/O Library. The io module is now the standard way of 
doing file I/O, and the initial values of sys.stdin, sys.stdout and 
sys.stderr are now instances of io.TextIOBase. The builtin open() 
function is now an alias for io.open() "


The 2.6.5 doc says
"io.open(file[, mode[, buffering[, encoding[, errors[, newline[, 
closefd=True]])¶


Open file and return a stream. If the file cannot be opened, an 
IOError is raised.


file is either a string giving the name (and the path if the file 
isn’t in the current working directory) of the file to be opened or a 
file descriptor of the file to be opened. "


If you are right, then "The builtin open() function is now an alias for 
io.open() " is misleading and does not apply to 2.6 even though it 
appears in an entry on things backported to 2.6. I do not really care.


tjr







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


Re: Limitation of os.walk

2010-05-12 Thread Terry Reedy

On 5/12/2010 2:52 PM, kj wrote:

In  Tim Chase writes:

  05/11/2010 09:07 PM, Terry Reedy wrote:

If os.walk were rewritten, it should be as an iterator (generator).
Directory entry and exit functions could still be added as params.



It *is* an iterator/generator.  However, I suspect you mean that
it should slurp the dirs/files iteratively instead of using
listdir() as was discussed on c.l.p a few months back.


Yes, I was thinking of that thread.


Thanks for mentioning this thread.  Very interesting stuff.  Apropos
the implementability of an iterative listdir, I wonder if some
variation of glob.iglob() would fit the bill.  (Maybe it's too
slow, though.)


I suspect if I thought about it much longer, only one would
really be needed, the other accommodated by the "topdown" parameter.


Yeah, I think one only needs a post hook.  The fact that it's a
generator obviates need for a pre hook, since the yield returns
control to the calling function right around where the pre-hook
would run anyway.  For the same reason, the post hook is needed
only for the case topdown=True.


Once you have determined and tested the minimal needed change for 
greater functionality, you could either

a) post a suggestion and the revised os.walk to python-ideas
b) submit a feature request to the tracker and attach the revised 
function and, if possible, a diff patch

c) both.

I have no idea of the response.

Terry Jan Reedy

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


Re: buffer objects (C-API)

2010-05-12 Thread Carl Banks
On May 12, 7:33 pm, moerchendiser2k3  wrote:
> Hi at all,
>
> is it possible that a buffer object deallocates the memory when the
> object is destroyed? I want to wrap the buffer object around some
> memory. Or is there any chance that the buffer object copies the
> memory so it will be responsible when it will be destroyed?


Objects that support the buffer protocol will only deallocate their
memory if they're programmed to.

If you're writing your own buffer type you can be assured the memory
won't be deallocated unless you do it yourself.

If you're referring to the Python 2.x "buffer" object, no it won't
deallocate the memory.  You should also be aware that it's deprecated
in 2.x and removed in 3.x.

Generally speaking, objects that allocate their own memory should also
deallocate it; objects that are passed pointers to existing memory
should leave it alone.  Most built-in types in Python that support
buffer protocol do allocate their own memory, so they also deallocate
it.  "buffer" doesn't, so it doesn't.

One other thing to consider is numpy, especially if your buffer is
numeric.  It might even have the operations you need already.
numpy.ndarray can allocate its own memory or accept a pointer (or
other buffer object), and will only delete the buffer if it allocated
it itself.


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


Re: Limitation of os.walk

2010-05-12 Thread Steven D'Aprano
On Wed, 12 May 2010 19:04:47 +, kj wrote:

> In  Terry Reedy
>  writes:
> 
>>On 5/11/2010 3:49 PM, kj wrote:
>>> PS: I never understood why os.walk does not support hooks for key
>>> events during such a tree traversal.
> 
>>Either 1) it is intentionally simple, with the expectation that people
>>would write there own code for more complicated uses or 2) no one has
>>submitted a 'full-featured' version or 3) both.
> 
> I hope it's not (1): I want the language I use to include more
> "batteries" not fewer.

How many more? Ten? Twenty? A hundred? Ten thousand? Ten million? Where 
do you draw the line?

Every extra battery is (say) a hundred extra lines of code, which means 
fifty thousand more potential bugs. It means more burden on the 
maintainers, and more burden on people learning the language. More 
batteries can make it more, not less, difficult to code:

# Python 1.1
"I need a collection of values, should I use a list, a tuple or a dict?"

vs

# Python 5000:
"I need a collection of values, should I use a list, a tuple, a dict, an 
array, a bag, a SortedBag, a table, a SortedTable, a NamedTuple, a 
Record, a stack, a queue, a deque, a linked list, a HashTable, a doubly-
linked list, a set, a frozenset, a skip list, a jump list, a binary tree, 
a  B tree, a B+ tree, a SortedList, a red-black tree, an A* tree, a B* 
tree, a SortedList, a StringList, a CaseInsensitiveSortedStringList, a 
CaseInsensitiveRedBlackTree, a HashSet, a CaseInsensitiveHashSet, an 
ArrayList, a ConcurrentQueue, a ConcurrentStack, a KeyedCollection, an 
EnumerableBag, a MultiSet, a StringMultiSet, a SortedSet, a 
DoubleEndedQueue, a Buffer, a CircularQueue, a heap, a binary search 
tree, an AssociatedArray, a Vector, a SparseArray, an XOR-linked list, a 
weight-balanced tree, a RandomizedBinarySearchTree, a ThreadedBinaryTree, 
an AVL tree, a splay tree, a rope, a binomial heap, a fibonacci heap, a 
trie, a B-trie, a judy array, an and/or tree, an enfilade, a treap, a 
dancing tree, a queap, or a fusion tree?" (Whew!)


There's nothing wrong with the existence of all these data structures. If 
you need one, you can use it. But they don't all need to be included in 
the standard library. That just increases the cognitive load on 
programmers without really adding that much benefit. I've seen people 
stress over the choice of a tuple or a list.



> It seems that a similar "simplicity argument" was invoked to
> strip the cmp option from sort in Python 3.  G.  Simplicity is
> great, but when the drive for it starts causing useful functionality to
> be thrown out, then it is going too far.  Yes, I know that it is
> possible to do everything that sort's cmp option does through clever
> tricks with key, 

Not that clever. In general, key-based sorting is simpler than cmp-based 
sorting. In addition, the use of a key function is a basic technique 
which every coder should have in their mental toolbox, and it is 
applicable to more than just sorting. E.g. max() and min() also support 
key functions in Python 2.6 and better. On the other hand a cmp function 
is specific to sorting, and nothing but sorting.



> but grokking and coding this maneuver requires a *lot*
> more Python-fu than cmp did, which makes this functionality a lot less
> accessible to beginners that the intrinsic complexity of the problem
> warrants.

I disagree that key-based sorting requires any more Python-fu than cmp 
sorting. I believe they're equivalent. There are cmp functions you can 
write which aren't (easily?) convertible to key, but most of them (all?) 
aren't useful or sensible. E.g. they rely on side-effects, don't define a 
sensible sort order, or break stability of sorting:

>>> text = "here is a number of words in some order".split()
>>>
>>> sorted(text, cmp=lambda a,b: cmp(a.upper(), b.lower()))
['order', 'some', 'in', 'words', 'of', 'number', 'a', 'is', 'here']
>>>
>>> sorted(text[2:] + text[:2], cmp=lambda a,b: cmp(a.upper(), b.lower()))
['is', 'here', 'order', 'some', 'in', 'words', 'of', 'number', 'a']


Key-based sorting doesn't let you do this, but since I can't think of any 
application where you want the sort order to be dependent on the initial 
order, I believe this is a good thing. It is much harder to write buggy 
sorts using key than with cmp.



> And for what?  To get rid of an *option* that could be easily
> disregarded by anyone who found it too "complex"? It makes no sense to
> me.


It's not that cmp is too complex, but that it's mere existence adds 
complexity to the list data type, it is usually slow and inefficient, and 
it can introduce subtle sorting bugs.


In the past, I've suggested that if people really believe that there is a 
use-case for sorting with a comparison function, they should fork it from 
the built-in list object and release it on PyPI as a third-party package. 
I still believe this.



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


Re: Picking a license

2010-05-12 Thread Lawrence D'Oliveiro
In message , Ed Keith 
wrote:

> ... but to claim that putting more restrictions on someone give them more
> freedom is pure Orwellian double speak.

What about the freedom to take away other people’s freedom? What tuple of 
speak would that be?
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >