Re:py 2.7.1 & openssl

2011-03-31 Thread nirinA raseliarison
[V N]
> I installed openssl-1.0.0d.tar.gz on my RHEL 5 box using:
>  ./config --prefix=/usr/local --openssldir=/usr/local/openssl
> shared zlib

you need to compile openssl with -fPIC flags,
depending on your system and compiler:

 ./config linux-generic:gcc -fPIC shared

and then recompile Python.
otherwise, look at the make log to see why
the building of ssl module failed.

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


Re: Guido rethinking removal of cmp from sort method

2011-03-31 Thread Steven D'Aprano
On Thu, 31 Mar 2011 01:34:17 -0500, harrismh777 wrote:

>  Many of you (Guido included) have lost significant sight of a
> critical object oriented philosophical pillar (but not all of you, thank
> goodness). To cut right to the heart of it--- NEVER change an advertised
> interface.


Thanks for your comments, M Harris, but I'm afraid you stumble right at 
the first step. The difference between implementation and interface is 
not specific to object-oriented code -- it is no more, or less, an 
"object oriented philosophical pillar" than it is a pillar of functional 
programming, procedural programming, or any other programming paradigm 
(except perhaps spaghetti coding).

Nor should you say "NEVER". To put your advice in other words:

"Once you have added a feature, no matter how badly thought out, broken, 
rarely used, or even actively hated by the entire programming community, 
you must continue supporting it forever, adding more and more cruft 
around it, just in case some obscure piece of software that hasn't been 
maintained for ten years relies on it."

Nobody has forgotten the principle of separating interface from 
implementation. This was not an accidental backwards incompatible 
change, it was a deliberate decision made in the full knowledge that it 
would be a painful move for some, but also in the expectation that *not* 
removing cruft becomes even more painful over time.

Cruft has real costs: maintenance costs, development costs, runtime 
costs, learning costs, and usability costs. Any language which does not 
prune cruft from time to time will ossify and is doing its users a real 
disservice. Just not too often.

Nobody is denying that the loss of list.sort(cmp=...) will hurt some 
people, or some use-cases. The disagreement is over the question of 
whether the pain from its loss outweighs the utility of its removal.

Python is about halfway through the expected migration period from 2.x to 
3.x, and so far it has not been worse or more difficult than expected. 
Support for Python 3 is about what was expected (probably better than 
expected), uptake of Python 3 by users is about what was expected, the 
number of nay-sayers, Negative Nellies and trolls claiming that Python 3 
will destroy the language is about what was expected, and the number of 
credible forks of the language promising to support Python 2 forever is 
exactly what was expected: zero.


[...]
> Many of us dropped JAVA
> (compile once debug everywhere) because it is complicated, a pita to
> use, slow, and actually doesn't port too well on any platform...

Perhaps that's because Java needs to drop some cruft.


> Many of us want to use the new 3.2+ version, but no one is going
> to ship it pre-installed (probably for many years) because of this
> issue.

Wrong. There is at least one Linux distro, Arch, which ships with Python3 
as the system Python. Arch is pretty bleeding edge, but where they go, 
others will follow.

Besides, "pre-installed" loses a lot of importance when installation is 
as easy as "sudo apt-get python3".


> There is no way to easily migrate, nor backport, and everyone is
> going to be forced to develop code (and have to maintain code) on two
> distinct branches (for many years to come).

Your FUD is outdated. There are now many major products which support 
Python 2 and 3, and some of them out of the same code base. Here is a 
small selection:

http://allanmcrae.com/2010/12/python-3-module-support/
http://mail.mems-exchange.org/durusmail/qp/441/
http://nedbatchelder.com/blog/200910/running_the_same_code_on_python_2x_and_3x.html

Note that last link is from 2009.



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


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Steven D'Aprano
On Wed, 30 Mar 2011 20:03:09 -0700, Joseph Sanoyo wrote:

> print "How old are you?", age = raw_input() print "How tall are you?",
> height = raw_input() print "How much do you weigh?", weight =
> raw_input() print "So, you're %r old, %r tall and %r heavy." % ( age,
> height, weight)
> Note:
> Notice that we put a , (comma) at the end of each print line. This is so
> that print doesn’t end the line with a newline and go to the next line.
> What You Should See
> Extra Credit
> 1. Go online and find out what Python’s raw_input does. $ python ex11.py
> How old are you?
> 35 How tall are you?
> 6'2" How much do you weigh? 180lbs
> So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
> 
> Related to escape sequences, try to find out why the last line has
> ’6\’2"’ with that \’ sequence. See how the single-quote needs to be
> escaped because otherwise it would end the string?

I'm sorry, are you asking a question and expecting an answer, replying to 
somebody else's question, or just sharing something you thought was 
interesting?


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


Re: Guido rethinking removal of cmp from sort method

2011-03-31 Thread Antoon Pardon
On Thu, Mar 31, 2011 at 02:13:53AM +, Steven D'Aprano wrote:
> On Wed, 30 Mar 2011 11:06:20 +0200, Antoon Pardon wrote:
> 
> > As far as I can see, key will only produce significant speedups, if
> > comparing items can then be completly done internally in the python
> > engine without referencing user python code.
> 
> Incorrect. You don't even need megabytes of data to see significant 
> differences. How about a mere 1000 short strings?
> 
> 
> [steve@wow-wow ~]$ python2.6
> Python 2.6.6 (r266:84292, Dec 21 2010, 18:12:50)
> [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from random import shuffle
> >>> data = ['a'*n for n in range(1000)]
> >>> shuffle(data)
> >>> from timeit import Timer
> >>>
> >>> t_key = Timer('sorted(data, key=lambda a: len(a))',
> ... 'from __main__ import data')
> >>> t_cmp = Timer('sorted(data, cmp=lambda a,b: cmp(len(a), len(b)))',
> ... 'from __main__ import data')
> >>>
> >>> min(t_key.repeat(number=1000, repeat=5))
> 0.89357517051696777
> >>> min(t_cmp.repeat(number=1000, repeat=5))
> 7.6032949066162109
> 
> That's almost ten times slower.

But how does it contradict what I wrote above? Maybe I didn't make
myself clear but in your example, the key function produces ints.
With ints the comparison is completely done within the python engine
without the need to defer to user python code (through the rich
comparison functions). So this is the kind of key I described that
would produce a significant speedup.

But once your key produces user objects that need to be compared
through user python code with __lt__ methods, getting a speedup
through the use of key instead of cmp will not be obvious and
in a number of case you will loose speed.

> Of course, the right way to do that specific sort is:
> >>> t_len = Timer('sorted(data, key=len)', 'from __main__ import data')
> >>> min(t_len.repeat(number=1000, repeat=5))
> 0.64559602737426758
> 
> which is even easier and faster. But even comparing a pure Python key 
> function to the cmp function, it's obvious that cmp is nearly always 
> slower.

I don't find that obvious at all. 

> Frankly, trying to argue that cmp is faster, or nearly as fast, is a 
> losing proposition. In my opinion, the only strategy that has even a 
> faint glimmer of hope is to find a convincing use-case where speed does 
> not matter.

I don't argue such a general statement. I just argue there are cases
where it is and I supporeted that statement with numbers. The only
way these numbers could be disputed was by focussing on specific details
that didn't generalize.

Now maybe providing a cmp_to_key function written in C, can reduce
the overhead for such cases as Raymond Hettinger suggested. If it
turns out that that works out, then I would consider this thread
usefull even if that will be the only result of this thread.

Something else the dev team can consider, is a Negation class.
This class would wrap itself around a class or object but reverse the ordering.
So that we would get Negation('a') > Negation('b'). That would make it
easy to create sort keys in which partial keys had to be sorted differently
from each other. This would have to be done by the dev team since I
guess that writing such a thing in Python would loose all the speed
of using a key-function.

> Or, an alternative approach would be for one of the cmp-supporters to 
> take the code for Python's sort routine, and implement your own sort-with-
> cmp (in C, of course, a pure Python solution will likely be unusable) and 
> offer it as a download. For anyone who knows how to do C extensions, this 
> shouldn't be hard: just grab the code in Python 2.7 and make it a stand-
> alone function that can be imported. 
> 
> If you get lots of community interest in this, that is a good sign that 
> the solution is useful and practical, and then you can push to have it 
> included in the standard library or even as a built-in.
> 
> And if not, well, at least you will be able to continue using cmp in your 
> own code.

I'll first let Raymond Hettinger rewrite cmp_to_key in C, as I understand he
suggested, and reevaluate after that.

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


Re: Guido rethinking removal of cmp from sort method

2011-03-31 Thread Paul Rubin
Antoon Pardon  writes:
> Something else the dev team can consider, is a Negation class
> This would have to be done by the dev team since I
> guess that writing such a thing in Python would loose all the speed
> of using a key-function.

That is a good idea.  SQL has something like it, I think, and Haskell
also has it.  I thought about writing it in Python but it would slow
things down a lot.  I hadn't thought of writing it in C for some reason.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: argparse csv + choices

2011-03-31 Thread Neal Becker
Robert Kern wrote:

> On 3/30/11 10:32 AM, Neal Becker wrote:
>> I'm trying to combine 'choices' with a comma-seperated list of options, so I
>> could do e.g.,
>>
>> --cheat=a,b
>>
>>  parser.add_argument ('--cheat', choices=('a','b','c'), type=lambda x:
>> x.split(','), default=[])
>>
>> test.py --cheat a
>>   error: argument --cheat: invalid choice: ['a'] (choose from 'a', 'b', 'c')
>>
>> The validation of choice is failing, because parse returns a list, not an
>> item. Suggestions?
> 
> Do the validation in the type function.
> 
> 
> import argparse
> 
> class ChoiceList(object):
>  def __init__(self, choices):
>  self.choices = choices
> 
>  def __repr__(self):
>  return '%s(%r)' % (type(self).__name__, self.choices)
> 
>  def __call__(self, csv):
>  args = csv.split(',')
>  remainder = sorted(set(args) - set(self.choices))
>  if remainder:
>  raise ValueError("invalid choices: %r (choose from %r)" %
> (remainder, self.choices))
>  return args
> 
> 
> parser = argparse.ArgumentParser()
> parser.add_argument('--cheat', type=ChoiceList(['a','b','c']), default=[])
> print parser.parse_args(['--cheat=a,b'])
> parser.parse_args(['--cheat=a,b,d'])
> 

Excellent!  Thanks!

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


EuroPython 2011: call for paper is ending - Please spread the word!

2011-03-31 Thread Palla
Hi all members,
I'm Francesco and I am writing on behalf of "Python Italia APS", a no-
profit association promoting EuroPython conference.
(www.europython.eu)

Europython end of Call for Presentations is April 6th. I'd like to ask
to you to forward this mail to anyone that you feel may be interested.

We're looking for proposals on every aspects of Python: programming
from novice to advanced levels, applications and frameworks, or how
you have been involved in introducing Python into your organisation.

**First-time speakers are especially welcome**; EuroPython is a
community conference and we are eager to hear about your experience.
If you have friends or colleagues who have something valuable to
contribute, twist their arms to tell us about it!


Presenting at EuroPython

We will accept a broad range of presentations, from reports on
academic and commercial projects to tutorials and case studies. As
long as the presentation is interesting and potentially useful to the
Python community, it will be considered for inclusion in the
programme.

Can you show the conference-goers something new and useful? Can you
show attendees how to: use a module? Explore a Python language
feature? Package an application? If so, consider submitting a talk.


Talks and hands-on trainings

There are two different kind of presentations that you can give as a
speaker at EuroPython:

 * **Regular talk**. These are standard "talk with slides", allocated
in slots of 45, 60 or 90 minutes, depending on your preference and
scheduling constraints. A Q&A session is held at the end of the talk.
 * **Hands-on training**. These are advanced training sessions for a
smaller audience (10-20 people), to dive into the subject with all
details. These sessions are 4-hours long, and audience will be
strongly encouraged to bring a laptop to experiment. They should be
prepared with less slides and more source code. If possible, trainers
will also give a short "teaser talk" of 30 minutes the day before the
training, to tease delegates into attending the training.

In the talk submission form, we assume that you intend to give a
regular talk on the subject, but you will be asked if you are
available for also doing a hands-on training on the very same subject.

Speakers that will give a hands-on training are rewarded with a **free
entrance** to EuroPython to compensate for the longer preparation
required, and might also be eligible for a speaking fee (which we
cannot confirm at the moment).

Topics and goals

Specific topics for EuroPython presentations include, but are not
limited to:

- Core Python
- Other implementations: Jython, IronPython, PyPy, and Stackless
- Python libraries and extensions
- Python 3.x migration
- Databases
- Documentation
- GUI Programming
- Game Programming
- Network Programming
- Open Source Python projects
- Packaging Issues
- Programming Tools
- Project Best Practices
- Embedding and Extending
- Science and Math
- Web-based Systems

Presentation goals usually are some of the following:

- Introduce audience to a new topic they are unaware of
- Introduce audience to new developments on a well-known topic
- Show audience real-world usage scenarios for a specific topic (case
study)
- Dig into advanced and relatively-unknown details on a topic
- Compare different options in the market on a topic


Community-based talk voting
---
This year, for the first time in EuroPython history, the talk voting
process is fully public. Every partecipant gains the right to vote for
talks submitted during the Call For Papers, as soon as they commit to
their presence at the conference by buying a ticket. See all the
details in the talk voting[1] page.

Contacts

For any further question, feel free to contact the organizers at
i...@pycon.it. Thank you!

[1]: http://ep2011.europython.eu/talk-voting
-- 
http://mail.python.org/mailman/listinfo/python-list


EuroPython 2011: call for paper is ending - Please spread the word!

2011-03-31 Thread Palla
Hi all members,
I'm Francesco and I am writing on behalf of "Python Italia APS", a no-profit
association promoting EuroPython conference. (www.europython.eu)

Europython End of Call for Presentations is April 6th. I'd like to ask to
you to forward this mail to anyone that you feel may be interested.

We're looking for proposals on every aspects of Python: programming from
novice to advanced levels, applications and frameworks, or how you have been
involved in introducing Python into your organisation.

**First-time speakers are especially welcome**; EuroPython is a community
conference and we are eager to hear about your experience. If you have
friends or colleagues who have something valuable to contribute, twist their
arms to tell us about it!


Presenting at EuroPython

We will accept a broad range of presentations, from reports on academic and
commercial projects to tutorials and case studies. As long as the
presentation is interesting and potentially useful to the Python community,
it will be considered for inclusion in the programme.

Can you show the conference-goers something new and useful? Can you show
attendees how to: use a module? Explore a Python language feature? Package
an application? If so, consider submitting a talk.


Talks and hands-on trainings

There are two different kind of presentations that you can give as a speaker
at EuroPython:

 * **Regular talk**. These are standard "talk with slides", allocated in
slots of 45, 60 or 90 minutes, depending on your preference and scheduling
constraints. A Q&A session is held at the end of the talk.
 * **Hands-on training**. These are advanced training sessions for a smaller
audience (10-20 people), to dive into the subject with all details. These
sessions are 4-hours long, and audience will be strongly encouraged to bring
a laptop to experiment. They should be prepared with less slides and more
source code. If possible, trainers will also give a short "teaser talk" of
30 minutes the day before the training, to tease delegates into attending
the training.

In the talk submission form, we assume that you intend to give a regular
talk on the subject, but you will be asked if you are available for also
doing a hands-on training on the very same subject.

Speakers that will give a hands-on training are rewarded with a **free
entrance** to EuroPython to compensate for the longer preparation required,
and might also be eligible for a speaking fee (which we cannot confirm at
the moment).

Topics and goals

Specific topics for EuroPython presentations include, but are not limited
to:

- Core Python
- Other implementations: Jython, IronPython, PyPy, and Stackless
- Python libraries and extensions
- Python 3.x migration
- Databases
- Documentation
- GUI Programming
- Game Programming
- Network Programming
- Open Source Python projects
- Packaging Issues
- Programming Tools
- Project Best Practices
- Embedding and Extending
- Science and Math
- Web-based Systems

Presentation goals usually are some of the following:

- Introduce audience to a new topic they are unaware of
- Introduce audience to new developments on a well-known topic
- Show audience real-world usage scenarios for a specific topic (case study)
- Dig into advanced and relatively-unknown details on a topic
- Compare different options in the market on a topic


Community-based talk voting
---
This year, for the first time in EuroPython history, the talk voting process
is fully public. Every partecipant gains the right to vote for talks
submitted during the Call For Papers, as soon as they commit to their
presence at the conference by buying a ticket. See all the details in the
talk voting[1] page.

Contacts

For any further question, feel free to contact the organizers at
i...@pycon.it. Thank you!

[1]: http://ep2011.europython.eu/talk-voting


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


Re: running Python2 Python3 parallel concurrent

2011-03-31 Thread John Roth
On Mar 30, 7:05 pm, harrismh777  wrote:
> Greetings,
>
>      The purpose of this communique is to document a process for
> installing python2.7.1 in parallel with python3.2 on a concurrent
> desktop with independent idle and python path structure.
>
> ...
>
>      Kind regards,
>
>      m harris
>
>  python2-python3-parallel.txt
> 7KViewDownload

You might want to look at PEP 394, which is tentatively scheduled for
Python 3.3 and the next maintenance release of 2.7. As far as I can
tell, this pretty much solves the problem for Unixoid and MacOS
systems. PEP 397 is a first cut at doing the same thing for Windows.

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


Re: Get USB ID of a serial port through pyserial?

2011-03-31 Thread Tim Golden

On 30/03/2011 20:01, John Nagle wrote:

Is there some way to get the USB ID of a serial port through
pyserial on Linux and/or Windows? USB serial port devices have
device names determined by when they were plugged in. So, if
you have more than one USB serial device, you need the USB device's
built-in ID to figure out what's out there.

Is there a way to get that info portably?


I appreciate that you're after a portable solution and are
using pyserial, but since no-one's responded (publicly), then
let me at least offer a WMI solution which should work on
Windows:


import win32com.client

wmi = win32com.client.GetObject ("winmgmts:")
for usb in wmi.InstancesOf ("Win32_USBHub"):
  print usb.DeviceID



Now, that shows that WMI can "see" USB devices, but to
get from that database record to something more physical,
such as a disk drive or a COM port usually involves a
merry dance across the WMI namespace, essentially joining
to successive entity classes until you reach the one you
want.

If you think this might be worth pursuing for your case,
feel free to get back and ask.

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


Re: Guido rethinking removal of cmp from sort method

2011-03-31 Thread Terry Reedy

On 3/31/2011 2:34 AM, harrismh777 wrote:


breaking a fundamental law of object oriented programming... don't break
and advertised interface (particularly if it is useful and people are
actually making use of it!).
This is insane folks.


Each x.y version (starting with 2.3) is feature stable: just bug fixes, 
no additions (except as occasionally required to fix a bug), no 
removals. 2.x had few feature changes or removals, as it was planned and 
announced that all the big ones were being delayed to 3.x. 2.7 will be 
polished for years, depending on how long anyone is willing to work on 
it. I have been a bit surprised and disappointed that no 2.x fan has yet 
come forward (that I know of) to specifically help fix 2.7 bugs.



Guido does not need a use case; he just needs to restore the interface
that everyone expects. Put up a message to start to use key= instead,
and plan deprecation for something like five years out... this just


Python 3 was announced and as a mildly code breaking version at least 5 
years before it came out. Old-style classes were clearly doomed when the 
new object. The int division change was also decided on about that time.


I agree that it would have been better if the developer group had been 
large enough to make the transition more orderly, but ...
as it is, it was not until 2.7 was out that we took a really good look 
at library interfaces and found that 'public interface' was not as well 
defined as it should be for some modules. That is much clearer for many 
in 3.2.



In the mean time... I'm playing around with 3.2 and really liking it...


Good.


hoping that the world will actually be using it someday.


I already am and fully expect it to be the dominant version in not too 
many years. Some linux distributions have already made it the default. 
Others have and will hold back.


--
Terry Jan Reedy

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


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread eryksun ()
On Wednesday, March 30, 2011 11:03:09 PM UTC-4, JosephS wrote:
> print "How old are you?", age = raw_input()
> print "How tall are you?", height = raw_input()
> print "How much do you weigh?", weight = raw_input()
> print "So, you're %r old, %r tall and %r heavy." % ( age, height,
> weight)
> Note:
> Notice that we put a , (comma) at the end of each print line. This is
> so that print doesn’t end the line with a newline and go to the next
> line.
> What You Should See
> Extra Credit
> 1. Go online and find out what Python’s raw_input does.
> $ python ex11.py How old are you?
> 35 How tall are you?
> 6'2" How much do you weigh? 180lbs
> So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
> 
> Related to escape sequences, try to find out why the last line has
> ’6\’2"’ with that \’ sequence. See how the single-quote needs to be
> escaped because otherwise it would end the string?

There appears to be a formatting error here. The following works:

print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()
print "So, you're %r old, %r tall and %r heavy." % ( age, height, weight)

Regarding the escape sequence, your're using %r which shows the representation 
(repr) of the string. For example:

In [1]: [x for x in height]
Out[1]: ['6', "'", '2', '"']

In [2]: print height
6'2"

In [3]: [x for x in repr(height)]
Out[3]: ["'", '6', '\\', "'", '2', '"', "'"]

In [4]: print repr(height)
'6\'2"'

The characters stored in height are just 6'2", but you couldn't input the 
string like that as a variable since Python uses quotes to demarcate a string 
literal. The backslash escapes the quote so that the interpreter will treat it 
as a regular character. It's unnecessary to escape the double quote, on the 
other hand, since this string literal is marked with single quotes. If the 
string were instead inputted with double quotes, then the final double quote 
would have to be escaped, such as the following: height = "6'2\"". Finally, 
notice that in the output representation of the characters of repr(height) 
(Out[3]) that the backslash itself has to be escaped. Otherwise it would be 
interpreted as escaping the single quote that follows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 3:12 AM, eryksun ()  wrote:
> There appears to be a formatting error here.

So remind me again why Python likes whitespace to be significant?



:)

Chris Angelico
PS. Yes, I know "remind me again" is redundant. You have to make
mistakes when you troll, it's a moral imperative!
-- 
http://mail.python.org/mailman/listinfo/python-list


python 2.6 script for Ubuntu Enterprise Cloud

2011-03-31 Thread shrek
Greetings
  I am having some problems with one of the scripts below.  I wonder
if anyone has run into a similar issue or knows a fix?
Seems I need to configure the proxy for python.  I did it in image-
store-proxy file in /var/log.  Is that the right place?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 9:18 AM, Chris Angelico  wrote:

> On Fri, Apr 1, 2011 at 3:12 AM, eryksun ()  wrote:
> > There appears to be a formatting error here.
>
> So remind me again why Python likes whitespace to be significant?
>
> 
>

http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py 2.7.1 & openssl

2011-03-31 Thread V N
Thank you for your response. Here's some more information:

RHEL 5.3 / x86_64,  using gcc

I am now compiling openssl-1.0.0d using:
./config --prefix=/usr/local --openssldir=/usr/local/openssl -fPIC
shared threads zlib
I do have the logs for config, make and make install. There are no
errors in any of them. When I run make test, there are no errors
reported. And, the following files are created in /usr/local/lib64:
libssl.a, libssl.so, libcrypto.a, libcrypto.so.  Also, the binary
openssl is created in the bin directory.

When I compile Python, I do not get any errors. In fact, I am able to
import hashlib, ssl, md5  and
>>> hashlib.md5


The issue is only with setup tools. I tried the following:

tar xzf bin/setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
$PYHOME/bin/python setup.py build

I tried to see exactly what fails in the install:
sudo $PYHOME/bin/python setup.py install_lib  <== works fine
sudo $PYHOME/bin/python setup.py install_headers <== works fine
sudo $PYHOME/bin/python setup.py install_scripts <== get ERROR

  File "setup.py", line 94, in 
scripts = scripts,
  File "/usr/local/Python-2.7.1/lib/python2.7/distutils/core.py", line
138, in setup
ok = dist.parse_command_line()
  File "/export/home/vnori/setuptools-0.6c11/setuptools/dist.py", line
271, in parse_command_line
result = _Distribution.parse_command_line(self)
  File "/usr/local/Python-2.7.1/lib/python2.7/distutils/dist.py", line
467, in parse_command_line
args = self._parse_command_opts(parser, args)
  File "/export/home/vnori/setuptools-0.6c11/setuptools/dist.py", line
590, in _parse_command_opts
nargs = _Distribution._parse_command_opts(self, parser, args)
  File "/usr/local/Python-2.7.1/lib/python2.7/distutils/dist.py", line
523, in _parse_command_opts
cmd_class = self.get_command_class(command)
  File "/export/home/vnori/setuptools-0.6c11/setuptools/dist.py", line
395, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
  File "/export/home/vnori/setuptools-0.6c11/pkg_resources.py", line
1954, in load
entry = __import__(self.module_name, globals(),globals(),
['__name__'])
  File "/export/home/vnori/setuptools-0.6c11/setuptools/command/
install_scripts.py", line 3, in 
from easy_install import get_script_args, sys_executable, chmod
  File "/export/home/vnori/setuptools-0.6c11/setuptools/command/
easy_install.py", line 12, in 
import sys, os.path, zipimport, shutil, tempfile, zipfile, re,
stat, random
  File "/usr/local/Python-2.7.1/lib/python2.7/tempfile.py", line 34,
in 
from random import Random as _Random
  File "/usr/local/Python-2.7.1/lib/python2.7/random.py", line 49, in

import hashlib as _hashlib
  File "/usr/local/Python-2.7.1/lib/python2.7/hashlib.py", line 136,
in 
globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Python-2.7.1/lib/python2.7/hashlib.py", line 71, in
__get_builtin_constructor
import _md5
ImportError: No module named _md5

Any idea(s)?

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


Re: Get USB ID of a serial port through pyserial?

2011-03-31 Thread wisecracker
Hi John Nagle...

> Is there some way to get the USB ID of a serial port through pyserial on 
> Linux and/or
> Windows?

I`m surprised that the big guns on here haven`t helped...

Short answer no.

> USB serial port devices have device names determined by when they were 
> plugged in.

Yep and they are easy to find in 32 bit Windows, *nix, AmigaOS and Mac OSX...

> So, if you have more than one USB serial device, you need the USB device's 
> built-in
> ID to figure out what's out there. Is there a way to get that info portably?

No not your way, but let`s see if I can help...
It is difficult to detect USB-Serial that is" p-n-p" and able to be put into 
any USB port.

In Windows it will be given a COMx: device, in *.nix /dev/ttyUSBx, in AmigaOS 
SER: and
I don`t know for sure but in Mac OSX /dev/ttyUSBx too

OK, I`m NO coder by any stretch of the imagination; but I have vast experience 
on getting
things like this to work. watch for wordwrapping etc, etc...

Let`s think laterally; how would a 10 year old think?
Assumptions will be made but not necessarily written here.
For this to work there will need to be user intervention at some point.

To make your needs platform independent requires the sys module, the 
sys.platform part
of it. Also the os module is needed, (and maybe the time module), to create 
your own custom
module. NOTE:- Pyserial is NOT needed for this AT ALL!

Righto, assume that the computer is powered down. This is a crude example, 
without error
checking.

Plug in your USB-Serial adaptor into any random USB port.

Power up the computer to Windows 32 bit or Linux in your case.

# Linux first...

import os
import sys
global myportnumber
myportnumber = "0"
if sys.platform == linux2:
# To see if ttyUSBx exists.
os.system("ls /dev/ttyUSB*")
# If only one does then this will be yours.
# If more than one exists, remove your unit from the USB port.
raw_input("Remove the USB-Serial adaptor from the port then press 
ENTER:- ")
os.system("ls /dev/ttyUSB*")
# Now find out which number does not exist and that is yours also.
# Replace the adaptor back into the same port as it came out of.
# myportnumber = raw_input("ENTER the number ONLY of your adaptor and 
press RETURN:- ")
# Now set up the port to RAW and say 1200 bps.
# NOTE:- The whitespaces must be adhered to.
os.system("stty -F /dev/ttyUSB"+myportnumber+" 1200")
os.system("stty -F /dev/ttyUSB"+myportnumber+" raw")

# You are now ready to roll and use your USB-Serial port.

# Windows second.

import os
import sys
global myportnumber
myportnumber = "0"
if sys.platform == win32:
# To see if COMx exists.
os.system("MODE.COM")
# If only one does then this will be yours.
# If more than one exists, remove your unit from the USB port.
raw_input("Remove the USB-Serial adaptor from the port then press 
ENTER:- ")
os.system("MODE.COM")
# Now find out which number does not exist and that is yours also.
# Replace the adaptor back into the same port as it came out of.
# myportnumber = raw_input("ENTER the number ONLY of your adaptor and 
press RETURN:- ")
# Now set up the port to RAW and say 1200 bps.
# NOTE:- The whitespaces must be adhered to.
os.system("MODE COM"+myportnumber+": BAUD=1200 PARITY=N DATA=8 STOP=1 
to=on")

This is a starter and no doubt the Pros on here will take th p**s out of it...



--
73...

Bazza, G0LCU...

Team AMIGA...

http://homepages.tesco.net/wisecracker/

http://main.aminet.net/search?readme=wisecracker

http://mikeos.berlios.de/

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


Corrections... :/

2011-03-31 Thread wisecracker
Sorry but I typed that loy in manually so:-
# Linux...

if sys.platform == "linux2":

# myportnumber = raw_input(..

should read:-

myportnumber = raw_input(..

# Similarly for Windows...

if sys.platform == "win32":

# myportnumber = raw_input(

should also read:-

myportnumber = raw_input(


Sorry about that chap...



--
73...

Bazza, G0LCU...

Team AMIGA...

http://homepages.tesco.net/wisecracker/

http://main.aminet.net/search?readme=wisecracker

http://mikeos.berlios.de/

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


Re: multiprocessing Pool.imap broken?

2011-03-31 Thread Yang Zhang
The problem was that Pool shuts down from its finalizer:

http://stackoverflow.com/questions/5481104/multiprocessing-pool-imap-broken/5481610#5481610

On Wed, Mar 30, 2011 at 5:59 AM, eryksun ()  wrote:
> On Tuesday, March 29, 2011 9:44:21 PM UTC-4, Yang Zhang wrote:
>> I've tried both the multiprocessing included in the python2.6 Ubuntu
>> package (__version__ says 0.70a1) and the latest from PyPI (2.6.2.1).
>> In both cases I don't know how to use imap correctly - it causes the
>> entire interpreter to stop responding to ctrl-C's.  Any hints?  Thanks
>> in advance.
>>
>> $ python
>> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
>> [GCC 4.4.3] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> import multiprocessing as mp
>> >>> mp.Pool(1).map(abs, range(3))
>> [0, 1, 2]
>> >>> list(mp.Pool(1).imap(abs, range(3)))
>> ^C^C^C^C^\Quit
>
> It works fine for me on Win32 Python 2.7.1 with multiprocessing 0.70a1. So 
> it's probably an issue with the implementation on Linux.
>
> Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46)
> [MSC v.1500 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
 import multiprocessing as mp
 list(mp.Pool(1).imap(abs, range(3)))
> [0, 1, 2]
 mp.__version__
> '0.70a1'
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Yang Zhang
http://yz.mit.edu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing Pool.imap broken?

2011-03-31 Thread Yang Zhang
My self-reply tried to preempt your suggestion :)

On Wed, Mar 30, 2011 at 12:12 AM, kyle.j.con...@gmail.com
 wrote:
> Yang,
>
> My guess is that you are running into a problem using multiprocessing with
> the interpreter. The documentation states that Pool may not work correctly
> in this case.
>>
>> Note: Functionality within this package requires that the __main__ method
>> be importable by the children. This is covered in Programming guidelines
>> however it is worth pointing out here. This means that some examples, such
>> as the multiprocessing.Pool examples will not work in the interactive
>> interpreter.
>
> Hope this helps,
>
> Kyle
>
>
> On Tue, Mar 29, 2011 at 6:51 PM, Yang Zhang  wrote:
>>
>> On Tue, Mar 29, 2011 at 6:44 PM, Yang Zhang 
>> wrote:
>> > I've tried both the multiprocessing included in the python2.6 Ubuntu
>> > package (__version__ says 0.70a1) and the latest from PyPI (2.6.2.1).
>> > In both cases I don't know how to use imap correctly - it causes the
>> > entire interpreter to stop responding to ctrl-C's.  Any hints?  Thanks
>> > in advance.
>> >
>> > $ python
>> > Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
>> > [GCC 4.4.3] on linux2
>> > Type "help", "copyright", "credits" or "license" for more information.
>>  import multiprocessing as mp
>>  mp.Pool(1).map(abs, range(3))
>> > [0, 1, 2]
>>  list(mp.Pool(1).imap(abs, range(3)))
>> > ^C^C^C^C^\Quit
>> >
>>
>> In case anyone jumps on this, this isn't an issue with running from the
>> console:
>>
>> $ cat /tmp/go3.py
>> import multiprocessing as mp
>> print mp.Pool(1).map(abs, range(3))
>> print list(mp.Pool(1).imap(abs, range(3)))
>>
>> $ python /tmp/go3.py
>> [0, 1, 2]
>> ^C^C^C^C^C^\Quit
>>
>> (I've actually never seen the behavior described in the corresponding
>> Note at the top of the multiprocessing documentation.)
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



-- 
Yang Zhang
http://yz.mit.edu/
-- 
http://mail.python.org/mailman/listinfo/python-list


call php function from python

2011-03-31 Thread CrabbyPete
I have a python script that automatically loads wordpress, up to the
point that it asks for the admin password.
that is a php function call

function wp_install( $blog_title, $user_name, $user_email, $public,
$deprecated = '', $user_password = '' )

Is there a way to call this function from python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FBI wants public help solving encrypted notes from murder mystery

2011-03-31 Thread Joe Snodgrass
On Mar 30, 10:18 pm, "Stretto"  wrote:
> "Joe Snodgrass"  wrote in message
>
> news:c37e8e0b-a825-4ac5-9886-8828ab1fa...@x8g2000prh.googlegroups.com...
>
>
>
>
>
> > FBI cryptanalysis hasn’t decrypted notes from 1999 murder mystery
>
> >http://tinyurl.com/4d56zsz
>
> > The FBI is seeking the public's help in breaking the encrypted code
> > found in two notes discovered on the body of a murdered man in 1999.
>
> > The FBI says that officers in St. Louis, Missouri discovered the body
> > of 41-year-old Ricky McCormick on June 30, 1999 in a field and the
> > clues regarding the homicide were two encrypted notes found in the
> > victim's pants pockets.
>
> > The FBI says that despite extensive work by its Cryptanalysis and
> > Racketeering Records Unit (CRRU), and the American Cryptogram
> > Association, the meanings of those two coded notes remain a mystery
> > and McCormick's murderer has never been found. One has to wonder
> > though, if the FBI can't figure this out, who can? But I digress.
>
> > From the FBI: "The more than 30 lines of coded material use a
> > maddening variety of letters, numbers, dashes, and parentheses.
> > McCormick was a high school dropout, but he was able to read and write
> > and was said to be 'street smart.' According to members of his family,
> > McCormick had used such encrypted notes since he was a boy, but
> > apparently no one in his family knows how to decipher the codes, and
> > it's unknown whether anyone besides McCormick could translate his
> > secret language. Investigators believe the notes in McCormick's
> > pockets were written up to three days before his death."
>
> > "Standard routes of cryptanalysis seem to have hit brick walls," said
> > CRRU chief Dan Olson in a statement. To move the case forward,
> > examiners need another sample of McCormick's coded system-or a similar
> > one-that might offer context to the mystery notes or allow valuable
> > comparisons to be made. Or, short of new evidence, Olson said, "Maybe
> > someone with a fresh set of eyes might come up with a brilliant new
> > idea."
>
> > The FBI says it has always relied on public tips and other assistance
> > to solve crimes though breaking a code may represent a special
> > circumstance.
>
> > For larger images of the notes go here. [LINK]
>
> > If you have an idea how to break the code, have seen similar codes, or
> > have any information about the Ricky McCormick case, write to CRRU at
> > the following address:
>
> > FBI Laboratory
> > Cryptanalysis and Racketeering Records Unit
> > 2501 Investigation Parkway
> > Quantico, VA 22135
> > Attn: Ricky McCormick Case
>
> > There is no reward being offered, just the knowledge that you may be
> > solving an intriguing murder mystery, the FBI stated.
>
> No other information about the guy? It might help. If the note is of any use
> then people and places would be in it. If that is the case then it would
> help to know where he lived and some of the names of people he knows.
>
> The note seems like it may not be just encrypted but a sort of
> compression(or rather shorthand/jargon) was used. Was the guy a drug dealer?
> It could be a list of "clients" or information about where he sold drugs(the
> numbers look like street addresses or amounts.
>
> If these kinda notes were so common from this guy then surely the FBI should
> have many more?
>
> Seems like the FBI could do more if they wanted it really solved...

As to which crime was being committed, I'm going with numbers running
or loan sharking.  There's no reason for any crook to keep any record
of any other crime, except prostitution, where phone books come in
handy.

Thievery is not an honest business, and records of what went down,
where and with whom can only hurt you.  Unless of course, it's a grand
list of felonies that he was using to blackmail the participants.

But I can't see gathering that much info from blackmail.  I always
thought it involved one guy blackmailing one victim.  This would imply
a factory scale process, and he'd need some way to lure his prey into
the trap.

Of course, that WOULD be a good way to get murdered.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: call php function from python

2011-03-31 Thread John Bokma
CrabbyPete  writes:

> I have a python script that automatically loads wordpress, up to the
> point that it asks for the admin password.
> that is a php function call
>
> function wp_install( $blog_title, $user_name, $user_email, $public,
> $deprecated = '', $user_password = '' )
>
> Is there a way to call this function from python?

What do you mean with "loads" wordpress? I think the easiest thing to
do, and what I've done in the past, is to call Wordpress via its web
interface. I.e. instead of trying to find out how to call wp_install,
use the post method with the right data and the right URL.

-- 
John Bokma   j3b

Blog: http://johnbokma.com/Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing Pool.imap broken?

2011-03-31 Thread eryksun ()
For comparison, here's the debug info on Win32 Python 2.71. Multiprocessing on 
Windows seems like a very different beast (e.g. there's no way to fork).

Case 1:

In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop.
:import multiprocessing as mp
:import multiprocessing.util as util
:util.log_to_stderr(util.SUBDEBUG)
:
:print(list(mp.Pool(1).imap(abs, range(3
:--
[DEBUG/MainProcess] created semlock with handle 604
[DEBUG/MainProcess] created semlock with handle 644
[DEBUG/MainProcess] added worker
[DEBUG/MainProcess] doing set_length()
[DEBUG/PoolWorker-1] recreated blocker with handle 36
[DEBUG/PoolWorker-1] recreated blocker with handle 48
[INFO/PoolWorker-1] child process calling self.run()
[0, 1, 2]

Case 2:

In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop.
:import multiprocessing as mp
:import multiprocessing.util as util
:util.log_to_stderr(util.SUBDEBUG)
:pool=mp.Pool(1)
:print list(pool.imap(abs, range(3)))
:--
[DEBUG/MainProcess] created semlock with handle 604
[DEBUG/MainProcess] created semlock with handle 644
[DEBUG/MainProcess] added worker
[DEBUG/MainProcess] doing set_length()
[DEBUG/PoolWorker-1] recreated blocker with handle 24
[DEBUG/PoolWorker-1] recreated blocker with handle 32
[INFO/PoolWorker-1] child process calling self.run()
[0, 1, 2]


On Thursday, March 31, 2011 2:46:25 PM UTC-4, Yang Zhang wrote:
> The problem was that Pool shuts down from its finalizer:
> 
> http://stackoverflow.com/questions/5481104/multiprocessing-pool-imap-broken/5481610#5481610
> 
> On Wed, Mar 30, 2011 at 5:59 AM, eryksun ()  wrote:
> > On Tuesday, March 29, 2011 9:44:21 PM UTC-4, Yang Zhang wrote:
> >> I've tried both the multiprocessing included in the python2.6 Ubuntu
> >> package (__version__ says 0.70a1) and the latest from PyPI (2.6.2.1).
> >> In both cases I don't know how to use imap correctly - it causes the
> >> entire interpreter to stop responding to ctrl-C's.  Any hints?  Thanks
> >> in advance.
> >>
> >> $ python
> >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
> >> [GCC 4.4.3] on linux2
> >> Type "help", "copyright", "credits" or "license" for more information.
> >> >>> import multiprocessing as mp
> >> >>> mp.Pool(1).map(abs, range(3))
> >> [0, 1, 2]
> >> >>> list(mp.Pool(1).imap(abs, range(3)))
> >> ^C^C^C^C^\Quit
> >
> > It works fine for me on Win32 Python 2.7.1 with multiprocessing 0.70a1. So 
> > it's probably an issue with the implementation on Linux.
> >
> > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46)
> > [MSC v.1500 32 bit (Intel)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
>  import multiprocessing as mp
>  list(mp.Pool(1).imap(abs, range(3)))
> > [0, 1, 2]
>  mp.__version__
> > '0.70a1'
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> 
> -- 
> Yang Zhang
> http://yz.mit.edu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 4:54 AM, Dan Stromberg  wrote:
>
> http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
>

I was trolling, I know the reasons behind it. Anyway, most people
don't share code by email! (Actually, since you seem to be the author
of that page - could you address that particular point? I think it's
probably as big an issue as any of the others, to today's coders -
"code semantics get destroyed by forums/email/etc/etc/etc".)

Solution: All emailed code should begin with
from __future__ import braces
And there you are, out of your difficulty at once!

Chris Angelico
tongue still firmly stuck in cheek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 1:35 PM, Chris Angelico  wrote:

> On Fri, Apr 1, 2011 at 4:54 AM, Dan Stromberg  wrote:
> >
> > http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
> >
>
> I was trolling, I know the reasons behind it. Anyway, most people
> don't share code by email! (Actually, since you seem to be the author
> of that page - could you address that particular point? I think it's
> probably as big an issue as any of the others, to today's coders -
> "code semantics get destroyed by forums/email/etc/etc/etc".)
>
> Solution: All emailed code should begin with
> from __future__ import braces
> And there you are, out of your difficulty at once!
>

Updated:

http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html

Another I can only partially refute: If you're having an e-mail discussion
about code, some mailers like to reformat your code into a paragraph.
Needless to say, this is bad for pretty much all code, but pathological for
Python and other languages that use whitespace in a manner distinct from
basic paragraph-filling.

Some alternatives:

   - Use a proper code review tool instead - EG
Rietveld.

   - Use a wiki instead - sometimes with a  tag (EG,
   on Wikipedia ).
   - Use HTML e-mail and a  tag
  - Except this'll have problems with real <'s and >'s - which are
  common in Python and other languages.
  - You can pipe your Python through this
sedcommand to deal with real <'s and
>'s
 - sed -e 's//\>/g'
  - Note that this is no more onerous than running code through a code
  beautifier
   - Use a non-borken MUA like
   mutt  for such communications
   - Mail your code as an attachment.
-- 
http://mail.python.org/mailman/listinfo/python-list


In List Query -> None Case Sensitive?

2011-03-31 Thread Wehe, Marco
Hi,

I am doing a search through a list of files but the text the casing doesn't 
match. My list is all upper case but the real files are all different. Is there 
a smooth way of searching through the list without going full on regular 
expressions?

path = "V:\\Jinsy\\incoming\\assets"

media=["LIHOU ISLAND.MOV", "MVI_1449.MOV"]

def FindMedia(path):
result = []

for root, dirs, files in os.walk(path):
for iFile in files:

if iFile in media:
filePath = 
os.path.join(root, iFile)

result.append(filePath)

return result


for filePath in FindMedia(path):
log(filePath)



This is the real file name that I can't find:
Lihou Island.mov

Thanks a lot,
Marco
[sky]
Marco Wehe
Visual Effects TD
VFX/3D
BSkyB, Sky 2, Grant Way, Isleworth, Middlesex TW7 5QD
t: +44 (0) 20 7805 8035
f: +44 (0) 20 7805 6577
e: marco.w...@bskyb.com



Information in this email including any attachments may be privileged, 
confidential and is intended exclusively for the addressee. The views expressed 
may not be official policy, but the personal views of the originator. If you 
have received it in error, please notify the sender by return e-mail and delete 
it from your system. You should not reproduce, distribute, store, retransmit, 
use or disclose its contents to anyone. Please note we reserve the right to 
monitor all e-mail communication through our internal and external networks. 
SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and 
are used under licence. British Sky Broadcasting Limited (Registration No. 
2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home 
Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited 
(Registration No. 2340150) are direct or indirect subsidiaries of British Sky 
Broadcasting Group plc (Registration No. 2247735). All of the companies 
mentioned in this paragraph are incorporated in England and Wales and share the 
same registered office at Grant Way, Isleworth, Middlesex TW7 5QD.

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


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread eryksun ()
On Thursday, March 31, 2011 4:35:42 PM UTC-4, Chris Angelico wrote:
>
> I was trolling, I know the reasons behind it. Anyway, most people
> don't share code by email! (Actually, since you seem to be the author
> of that page - could you address that particular point? I think it's
> probably as big an issue as any of the others, to today's coders -
> "code semantics get destroyed by forums/email/etc/etc/etc".)
> 
> Solution: All emailed code should begin with
> from __future__ import braces
> And there you are, out of your difficulty at once!

You could paste it as a base64 stream, such as:


> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI=


Then decode and exec:

In [1]: import base64

In [2]: %cpaste
Pasting code; enter '--' alone on the line to stop.
:code="""> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
:> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI="""
:--

In [3]: print base64.b64decode(code)
def spam():
print "Spam! Lovely spam! Lovely spam!"

In [4]: exec(base64.b64decode(code))

In [5]: spam()
Spam! Lovely spam! Lovely spam!

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


Re: In List Query -> None Case Sensitive?

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 8:14 AM, Wehe, Marco  wrote:
>
> I am doing a search through a list of files but the text the casing doesn't 
> match. My list is all upper case but the real files are all different. Is 
> there a smooth way of searching through the list without going full on 
> regular expressions?
>
>             if iFile in media:

If you know they're *all* uppercase, the easiest way is to replace
this line with:

if iFile.upper() in media:

It's not case insensitive per se. For true case insensitivity, force
media[] to be all-uppercase too:

media=[f.upper() for f in media]

Or you can equally use lower() instead of upper().

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


Re: In List Query -> None Case Sensitive?

2011-03-31 Thread Ian Kelly
On Thu, Mar 31, 2011 at 3:14 PM, Wehe, Marco  wrote:

>  Hi,
>
>
>
> I am doing a search through a list of files but the text the casing doesn't
> match. My list is all upper case but the real files are all different. Is
> there a smooth way of searching through the list without going full on
> regular expressions?
>
>
if iFile.upper() in media:
# do stuff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In List Query -> None Case Sensitive?

2011-03-31 Thread Ethan Furman

Wehe, Marco wrote:
I am doing a search through a list of files but the text the casing 
doesn't match. My list is all upper case but the real files are all 
different. Is there a smooth way of searching through the list without 
going full on regular expressions?


path = "V:\\Jinsy\\incoming\\assets"
media=["LIHOU ISLAND.MOV", "MVI_1449.MOV"]
def FindMedia(path):
result = []
for root, dirs, files in os.walk(path):
for iFile in files:
if iFile in media:
filePath = os.path.join(root, iFile)
result.append(filePath)
return result
for filePath in FindMedia(path):
log(filePath)



Change

if iFile in media:

to

if iFile.upper() in media:

and keep media all upper-case.

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


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread geremy condra
On Thu, Mar 31, 2011 at 2:43 PM, eryksun ()  wrote:
> On Thursday, March 31, 2011 4:35:42 PM UTC-4, Chris Angelico wrote:
>>
>> I was trolling, I know the reasons behind it. Anyway, most people
>> don't share code by email! (Actually, since you seem to be the author
>> of that page - could you address that particular point? I think it's
>> probably as big an issue as any of the others, to today's coders -
>> "code semantics get destroyed by forums/email/etc/etc/etc".)
>>
>> Solution: All emailed code should begin with
>> from __future__ import braces
>> And there you are, out of your difficulty at once!
>
> You could paste it as a base64 stream, such as:
>
>
>> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
>> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI=
>
>
> Then decode and exec:
>
> In [1]: import base64
>
> In [2]: %cpaste
> Pasting code; enter '--' alone on the line to stop.
> :code="""> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
> :> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI="""
> :--
>
> In [3]: print base64.b64decode(code)
> def spam():
>    print "Spam! Lovely spam! Lovely spam!"
>
> In [4]: exec(base64.b64decode(code))
>
> In [5]: spam()
> Spam! Lovely spam! Lovely spam!

I know it's tongue-in-cheek, but please, please, please don't do this.

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


Re: logging module usage

2011-03-31 Thread Vinay Sajip
On Mar 30, 3:49 pm, mennis  wrote:
> I am working on a library for controlling various appliances in which
> I use theloggingmodule.  I'd like some input on the basic structure
> of what I've done.  Specifically theloggingaspect but more general
> comments are welcome.  I'm convinced I mis-understand something but
> I'm not sure what.  I've posted a version of the library at github.
>
> g...@github.com:mennis/otto.githttp://github.com/mennis/otto
> Ian

>From a quick glance over your code, looking only at the logging
perspective:

It's fine to use the Django-like approach to provide better
compatibility with Python versions < 2.5.

Your use of an extra level is also OK, but other applications and
tools won't know about your extra level, which could limit
interoperability. If your application is completely self contained,
however, that should be fine.

You don't really need to hold loggers as instance attributes in
objects - they are effectively singletons.

The convention is to use logger = getLogger(__name__), that way you
don't have to change your code to rename loggers if you move modules
around in a package.

Not sure why you are doing logging.disable() in code, this means that
you can't change the verbosity using configuration files.

You don't appear to be using the logger.exception() method in
exception handlers, thereby not putting tracebacks in the log.

You don't add a NullHandler to the root logger of your top-level
package, which you should.

I see you're using Python 2.x, but you may nevertheless find it useful
to look at the logging docs for Python 3.2. These have been split into
reference docs and HOWTOs, rather than the somewhat monolithic
approach taken in the 2.x docs.

Regards,

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


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 8:57 AM, geremy condra  wrote:
> I know it's tongue-in-cheek, but please, please, please don't do this.

It would be more secure to base64 it and then rot13 the output.

Chris Angelico
/me is feeling evil today

=== Begin Base-Rotten 64-13 ===
FKDtq291oTDtLzHtoJ9lMFOmMJA1pzHtqT8tLzSmMGL0VTy0VTShMPO0nTIhVUWiqQRmVUEbMFOi
qKEjqKDhQDbAPxAbpzymVRShM2IfnJAiQDbioJHtnKZtMzIyoTyhMlOyqzyfVUEiMTS5QDb=
=== End Base-Rotten 64-13 ===
-- 
http://mail.python.org/mailman/listinfo/python-list


Alias for an attribute defined in a superclass

2011-03-31 Thread Ben Finney
Howdy all,

I want to inherit from a class, and define aliases for many of its
attributes. How can I refer to “the attribute that will be available by
name ‘spam’ once this class is defined”?

class Foo(object):
def spam(self):
pass

def eggs(self):
pass

class Bar(Foo):
beans = Foo.spam
mash = Foo.eggs

Is that the right way to do it? Will that leave me open to “unbound
method” or “is not an instance of ‘Bar’” or other problems when using
‘Bar.beans’?

-- 
 \   “If [a technology company] has confidence in their future |
  `\  ability to innovate, the importance they place on protecting |
_o__) their past innovations really should decline.” —Gary Barnett |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Wing IDE 4.0.1 released

2011-03-31 Thread Wingware

Hi,

Wingware has released version 4.0.1 of Wing IDE, an integrated development
environment designed specifically for the Python programming language.

Wing IDE is a cross-platform Python IDE that provides a professional code
editor with vi, emacs, and other key bindings, auto-completion, call tips,
refactoring, a powerful graphical debugger, version control, unit testing,
search, and many other features.

**Changes in Version 4.0.1**

* Several fixes in source analysis, find uses, and refactoring
* Improves Django support and adds support for Django 1.3
* Adds support for 64-bit Python 3.2 on Windows
* Improves diff/merge for non-ascii text and on Windows
* Adds support for debugging Python with -O command line option
* Avoids a potential hang in the debugger with wx and gtk GUI apps
* Fixes a potential crash on long lines in the editor
* Fixes problems that could lead to failure to start
* About 40 other bug fixes and minor improvements

See the change log for details.

**New Features in Version 4.0**

Version 4.0 adds the following new major features:

* Refactoring -- Rename and move symbols, and extract code to function 
or method

* Find Uses -- Find all points of use of a symbol
* Diff/Merge -- Graphical file and repository comparison and merge
* Django Support -- Debug Django templates, run Django unit tests, and more
* matplotlib Support -- Maintains live-updating plots in shell and debugger
* Simplified Licensing -- Includes all OSes and adds Support+Upgrades 
subscriptions


Complete Change Log:   
http://wingware.com/pub/wingide/4.0.1/CHANGELOG.txt

Details on Licensing Changes:  http://wingware.com/news/2011-02-16

**About Wing IDE**

Wing IDE is an integrated development environment designed specifically for
the Python programming language.  It provides powerful editing, testing, and
debugging features that help reduce development and debugging time, cut down
on coding errors, and make it easier to understand and navigate Python code.
Wing IDE can be used to develop Python code for web, GUI, and embedded
scripting applications.

Wing IDE is available in three product levels:  Wing IDE Professional is
the full-featured Python IDE, Wing IDE Personal offers a reduced feature
set at a low price, and Wing IDE 101 is a free simplified version designed
for teaching beginning programming courses with Python.

Version 4.0 of Wing IDE Professional includes the following major features:

* Professional quality code editor with vi, emacs, and other keyboard
  personalities
* Code intelligence for Python:  Auto-completion, call tips, find uses,
  goto-definition, error indicators, refactoring, smart indent and 
rewrapping,

  and source navigation
* Advanced multi-threaded debugger with graphical UI, command line 
interaction,

  conditional breakpoints, data value tooltips over code, watch tool, and
  externally launched and remote debugging
* Powerful search and replace options including keyboard driven and 
graphical

  UIs, multi-file, wild card, and regular expression search and replace
* Version control integration for Subversion, CVS, Bazaar, git, 
Mercurial, and

  Perforce
* Integrated unit testing with unittest, nose, and doctest frameworks
* Django support:  Debugs Django templates, provides project setup tools,
  and runs Django unit tests
* Many other features including project manager, bookmarks, code snippets,
  diff/merge tool, OS command integration, indentation manager, PyLint
  integration, and perspectives
* Extremely configurable and may be extended with Python scripts
* Extensive product documentation and How-Tos for Django, matplotlib,
  Plone, wxPython, PyQt, mod_wsgi, Autodesk Maya, and many other frameworks

Please refer to http://wingware.com/wingide/features for a detailed listing
of features by product level.

System requirements are Windows 2000 or later, OS X 10.3.9 or later 
(requires
X11 Server), or a recent Linux system (either 32 or 64 bit).  Wing IDE 
supports

Python versions 2.0.x through 3.2.x and Stackless Python.

For more information, see the http://wingware.com/

**Downloads**

Wing IDE Professional and Wing IDE Personal are commercial software and
require a license to run. A free trial can be obtained directly from the
product when launched.

Wing IDE Pro -- Full-featured product:
http://wingware.com/downloads/wingide/4.0

Wing IDE Personal -- A simplified IDE:
http://wingware.com/downloads/wingide-personal/4.0

Wing IDE 101 -- For teaching with Python:
http://wingware.com/downloads/wingide-101/4.0

**Purchasing and Upgrading**

Wing 4.0 requires an upgrade for Wing IDE 2.x and 3.x users at a cost of
1/2 the full product pricing.

Upgrade a license:   https://wingware.com/store/upgrade
Purchase a new license:  https://wingware.com/store/purchase

--

The Wingware Team
Wingware | Python IDE
Advancing Software Development

www.wingware.com

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


a basic bytecode to machine code compiler

2011-03-31 Thread Rouslan Korneychuk
I was looking at the list of bytecode instructions that Python uses and 
I noticed how much it looked like assembly. So I figured it can't be to 
hard to convert this to actual machine code, to get at least a small 
boost in speed.


And so I whipped up a proof of concept, available at 
https://github.com/Rouslan/nativecompile


I'm aware that PyPy already has a working JIT compiler, but I figure it 
will be a long time before they have a version of Python that is ready 
for everybody to use, so this could be useful in the mean time.


I chose to create this for the latest stable version of Python and I 
happen to use some functionality that is only available since Python 3.2.


The basic usage is:

>>> import nativecompile
>>> bcode = compile('print("Hello World!")','','exec')
>>> mcode = nativecompile.compile(bcode)
>>> mcode()
Hello World!


This compiler does absolutely nothing clever. The only difference 
between the bytecode version and the compiled version is there is no 
interpreter loop and the real stack is used instead of an array.


Most of it is written in Python itself. There is one module written in C 
that does the things that cannot easily be done in pure Python, such as 
get the addresses of API functions and to execute the newly created code.


So far I have only implemented a few bytecode instructions and only have 
32-bit x86-compatible support. I have only tested this on Linux. It 
might work on Windows but only if you can run programs without any sort 
of data execution prevention (I can fix that if anyone wants). And I'm 
sure more optimized machine code can be generated (such as rearranging 
the error checking code to work better with the CPU's branch predictor).


Since so few instructions are implemented I haven't done any benchmarks.


What do people think? Would I be wasting my time going further with this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: py 2.7.1 & openssl

2011-03-31 Thread nirinA

[V N]

import _md5
ImportError: No module named _md5

Any idea(s)?


try to build Python with pydebug to enable _md5:

 ./configure --with-pydebug

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


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread John Bokma
Chris Angelico  writes:

> On Fri, Apr 1, 2011 at 8:57 AM, geremy condra  wrote:
>> I know it's tongue-in-cheek, but please, please, please don't do this.
>
> It would be more secure to base64 it and then rot13 the output.

Rot-13 twice, to make it even more secure ;-)


-- 
John Bokma   j3b

Blog: http://johnbokma.com/Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Behaviour of subprocess.Popen, ssh and nohup I don't understand

2011-03-31 Thread Adriaan Renting
L.S.

I have a problem that a background process that I'm trying to start with
subprocess.Popen gets interrupted and starts waiting for input no matter
what I try to do to have it continue to run. It happens when I run it
with nohup in the background.
I've tried to find a solution searching the internet, but found none.
I've written a small test script that reproduces the problem and hope
maybe here there is someone who can tell me what's going wrong. Any
suggestions are welcome.

(renting)myhost> cat test.py
#!/usr/bin/python
# script to test subprocess problem
import subprocess, sys, time

for f in range(3):
  command = ["ssh", "-T", "localhost", "uptime"]
  comm = subprocess.Popen(command, shell=False, stdin=None,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
  print  '1'
  if comm.returncode:
print "error: %i" % (comm.return_code)
  else:
print  '2'
(output, output2) = comm.communicate(input=None)
print output
print output2 
  print  '3'
  time.sleep(3)

(renting)myhost> python --version
Python 2.5.2

(renting)myhost> nohup ./test.py -O2 &
[1] 15679

(renting)myhost> 1
2
 22:40:30 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00

None
3
1
2

[1]  + Suspended (tty input) ./test.py -O2
(renting)myhost> fg
./test.py -O2

 22:40:35 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00

None
3
1
2
 22:40:56 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00

None
3

(renting)myhost>

Now as you can see, it suspends on the second time through the for loop,
until I bring it to the foreground and hit .
What you don't see, is that I make it do this by pushing the arrow keys
a couple of times. The same happens when I would exit the shell, despite
it running with nohup.
I don't need to exit to make it suspend, any combination of a few random
keystrokes makes it do this. It seems depending on the timing though,
during the sleep(3) it seems to ignore me, only when subprocess is
actually running will it suspend if I generate keystrokes.
If the ssh command is executed without -T option it suspends directly,
so I think it's related to the ssh command. I log in with a
public/private key pair to avoid having to enter a password.

Any suggestions are welcome,

thanks,

Adriaan Renting

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


Re: py 2.7.1 & openssl

2011-03-31 Thread V N
Yes, _md5 is enabled but I get a very long list under

Failed to build these modules:
_bisect_codecs_cn _codecs_hk
_codecs_iso2022_codecs_jp _codecs_kr
_codecs_tw _collections   _csv
_ctypes_ctypes_test   _curses
_curses_panel  _elementtree   _functools
_hashlib   _heapq _hotshot
_io_json  _locale
_lsprof_multibytecodec_multiprocessing
_random_socket_sqlite3
_ssl   _struct_testcapi
array  audioopbinascii
bz2cmath  cPickle
crypt  cStringIO  datetime
fcntl  future_builtinsgrp
itertools  linuxaudiodev  math
mmap   nisoperator
ossaudiodevparser pyexpat
readline   resource   select
spwd   strop  syslog
termiostime   unicodedata
zlib

This list was empty earlier.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In List Query -> None Case Sensitive?

2011-03-31 Thread Steven D'Aprano
On Thu, 31 Mar 2011 21:14:45 +, Wehe, Marco wrote:
[...]

Hi Marco, and welcome.

Others have already answered your question, but please don't post HTML 
formatted messages (so-called "rich text") to this mailing list. It is 
mirrored to a newsgroup, comp.lang.python, and many people read it via 
that. To many of those people your message will be entirely blocked due 
to the use of HTML code, and for many of the remaining, they will see 
this:

>  xmlns:o="urn:schemas-microsoft-com:office:office"
> xmlns:w="urn:schemas-microsoft-com:office:word"
> xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
> xmlns="http://www.w3.org/TR/REC-html40";
> xmlns:ns1="urn:schemas-microsoft-com:office:smarttags"> 
> 
>   content="Microsoft Word 11"> 

which then goes on in that style for another NINE PAGES.

(Oh, and I don't want to come across as elitist, but if you're using the 
two-ton wrecking ball of Microsoft Word to crack the tiny peanut of 
writing emails, you will have *zero* tech credibility in programming 
communities. Harsh but true. Sorry Marco, but mastery of tools is 
important to programmers, and a tool that generates as crufty HTML as 
Word does will unfortunately reflect badly on the person using the tool.)



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


Re: cx_Freeze 4.2.3

2011-03-31 Thread James Mills
On Sun, Mar 20, 2011 at 9:52 AM, Anthony Tuininga
 wrote:
> Where do I get it?
>
> http://cx-freeze.sourceforge.net

Just as a matter of interest, I tried to install cx_Freeze with
pip/distribute (Python 2.7.1)
but it fails with:

error: option --single-version-externally-managed not recognized

cheers
James

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


Re: In List Query -> None Case Sensitive?

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 10:42 AM, Steven D'Aprano
 wrote:
> (Oh, and I don't want to come across as elitist, but if you're using the
> two-ton wrecking ball of Microsoft Word to crack the tiny peanut of
> writing emails, you will have *zero* tech credibility in programming
> communities. Harsh but true. Sorry Marco, but mastery of tools is
> important to programmers, and a tool that generates as crufty HTML as
> Word does will unfortunately reflect badly on the person using the tool.)

There are the mistakes (nearly) everyone makes when new. I think HTML
email might be one of them.

The difference between a good programmer and a mediocre one is that
the good programmer has already made a lot of mistakes, and has
learned from them. The difference between an excellent programmer and
a good one is that the excellent one is familiar with a huge number of
tools, and knows which one is best for which situation. A two-ton
wrecking ball is not the best tool for cracking peanuts; Microsoft
Word is not the best tool for... well, anything, probably. My boss at
work laughs sometimes at the weird variety of tools I crack out in
response to various problems - today it's awk, tomorrow sed, the next
day some two-minute script in Python, Pike, bash, PHP, or REXX
ever noticed how beautiful chaos can be? :)

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


Re: a basic bytecode to machine code compiler

2011-03-31 Thread Stefan Behnel

Rouslan Korneychuk, 01.04.2011 00:33:

I was looking at the list of bytecode instructions that Python uses and I
noticed how much it looked like assembly. So I figured it can't be to hard
to convert this to actual machine code, to get at least a small boost in
speed.


I think I recall having read about something like this before, but I can't 
quite find it. In any case, you may want to take a look at both Cython and 
Psyco.


Stefan

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


Re: In List Query -> None Case Sensitive?

2011-03-31 Thread MRAB

On 31/03/2011 23:05, Ethan Furman wrote:

Wehe, Marco wrote:

I am doing a search through a list of files but the text the casing
doesn't match. My list is all upper case but the real files are all
different. Is there a smooth way of searching through the list without
going full on regular expressions?

path = "V:\\Jinsy\\incoming\\assets"
media=["LIHOU ISLAND.MOV", "MVI_1449.MOV"]
def FindMedia(path):
result = []
for root, dirs, files in os.walk(path):
for iFile in files:
if iFile in media:
filePath = os.path.join(root, iFile)
result.append(filePath)
return result
for filePath in FindMedia(path):
log(filePath)



Change

if iFile in media:

to

if iFile.upper() in media:

and keep media all upper-case.



Converting to uppercase or lowercase doesn't always work as desired.

For example, when using Turkish you can have problems, because the
Turkish variant of the Latin alphabet splits i/I into two different
letters, namely dotted "i" (uppercase is "İ" or "\u0130") and dotless
"I" (lowercase is "ı" or "\u0131").

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


Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Steven D'Aprano
On Fri, 01 Apr 2011 09:14:03 +1100, Ben Finney wrote:

> Howdy all,
> 
> I want to inherit from a class, and define aliases for many of its
> attributes. 

Are these aliases of arbitrary aliases, or only of methods, as in your 
example below?


> How can I refer to “the attribute that will be available by
> name ‘spam’ once this class is defined”?

You might be able to use the descriptor protocol to do something like 
that, but otherwise I don't think you can. However, I note that your 
example isn't *quite* how you describe it above.


> class Foo(object):
> def spam(self):
> pass
> def eggs(self):
> pass
> 
> class Bar(Foo):
> beans = Foo.spam
> mash = Foo.eggs

This assigns the name Bar.beans to the method object Foo.spam. If you now 
rebind the name Foo.spam to something else, Bar.beans will not likewise 
change, but will continue to refer to the original. This is contrary to 
your earlier description, where Bar.beans should also change.

This is no different from the usual Python namespace behaviour:

x = 42
y = x

y is an alias to x, until you rebind x. For variables, you can't change 
the behaviour; for attributes of a class, you may be able to write a 
descriptor to do something along those lines.


> Is that the right way to do it? Will that leave me open to “unbound
> method” or “is not an instance of ‘Bar’” or other problems when using
> ‘Bar.beans’?

I don't believe so. So long as you don't rebind the "alias" or the 
original, you should be fine.


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


Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Calvin Spealman
Sounds like you're just going to end up with more confusing code
having multiple ways to refer to the exact same thing. Why?

On Thu, Mar 31, 2011 at 6:14 PM, Ben Finney  wrote:
> Howdy all,
>
> I want to inherit from a class, and define aliases for many of its
> attributes. How can I refer to “the attribute that will be available by
> name ‘spam’ once this class is defined”?
>
>    class Foo(object):
>        def spam(self):
>            pass
>
>        def eggs(self):
>            pass
>
>    class Bar(Foo):
>        beans = Foo.spam
>        mash = Foo.eggs
>
> Is that the right way to do it? Will that leave me open to “unbound
> method” or “is not an instance of ‘Bar’” or other problems when using
> ‘Bar.beans’?
>
> --
>  \           “If [a technology company] has confidence in their future |
>  `\      ability to innovate, the importance they place on protecting |
> _o__)     their past innovations really should decline.” —Gary Barnett |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
-- 
http://mail.python.org/mailman/listinfo/python-list


Extracting subsequences composed of the same character

2011-03-31 Thread candide

Suppose you have a string, for instance

"pyyythhooonnn ---> "

and you search for the subquences composed of the same character, here 
you get :


'yyy', 'hh', 'ooo', 'nnn', '---', ''

It's not difficult to write a Python code that solves the problem, for 
instance :


def f(text):
ch=text
r=[]
if not text:
return r
else:
x=ch[0]
i=0
for c in ch:
if c!=x:
if i>1:
r+=[x*i]
x=c
i=1
else:
i+=1
return r+(i>1)*[i*x]

print f("pyyythhooonnn ---> ")


I should confess that this code is rather cumbersome so I was looking 
for an alternative. I imagine that a regular expressions approach could 
provide a better method. Does a such code exist ?  Note that the string 
is not restricted to the ascii charset.

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


Re: a basic bytecode to machine code compiler

2011-03-31 Thread Terry Reedy

On 3/31/2011 6:33 PM, Rouslan Korneychuk wrote:

I was looking at the list of bytecode instructions that Python uses and
I noticed how much it looked like assembly. So I figured it can't be to
hard to convert this to actual machine code, to get at least a small
boost in speed.

And so I whipped up a proof of concept, available at
https://github.com/Rouslan/nativecompile

I'm aware that PyPy already has a working JIT compiler, but I figure it
will be a long time before they have a version of Python that is ready
for everybody to use, so this could be useful in the mean time.


I believe PyPy folk think it ready now, at least for some uses. 
Speedwise, it is more or less is now comparable to CPython, winning some 
benchmarks, losing others.

...

What do people think? Would I be wasting my time going further with this?


Depends on whether your goal is personal (learning, fun, use) or 
usefulness to others. For the latter, you *might* do better to help with 
an existing project, such as Cython or Dufour's ShedSkin.


--
Terry Jan Reedy

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


Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Ben Finney
Calvin Spealman  writes:

> Sounds like you're just going to end up with more confusing code
> having multiple ways to refer to the exact same thing. Why?

(Why did you top-post?)

I'm defining aliases to conform to an existing API. The “Foo” class's
attributes are what is needed, but not by the right names. So I'm making
a subclass “Bar” to provide those same attributes by the names required
by the third-party API.

-- 
 \  “He that loveth father or mother more than me is not worthy of |
  `\me: and he that loveth son or daughter more than me is not |
_o__)worthy of me.” —Jesus, as quoted in Matthew 10:37 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Ben Finney
Steven D'Aprano  writes:

> On Fri, 01 Apr 2011 09:14:03 +1100, Ben Finney wrote:
>
> > I want to inherit from a class, and define aliases for many of its
> > attributes.
>
> Are these aliases of arbitrary aliases, or only of methods, as in your
> example below?

I'd like to know how to do either, for making API wrapper classes.

> > How can I refer to “the attribute that will be available by
> > name ‘spam’ once this class is defined”?
>
> You might be able to use the descriptor protocol to do something like
> that, but otherwise I don't think you can. However, I note that your
> example isn't *quite* how you describe it above.

Yes, I got the names wrong. The example is accurate to what I'm meaning
to say.

> > class Foo(object):
> > def spam(self):
> > pass
> > def eggs(self):
> > pass
> > 
> > class Bar(Foo):
> > beans = Foo.spam
> > mash = Foo.eggs
>
> This assigns the name Bar.beans to the method object Foo.spam. If you
> now rebind the name Foo.spam to something else, Bar.beans will not
> likewise change, but will continue to refer to the original. This is
> contrary to your earlier description, where Bar.beans should also
> change.

Hmm. I think I can live with that limitation.

> > Is that the right way to do it? Will that leave me open to “unbound
> > method” or “is not an instance of ‘Bar’” or other problems when
> > using ‘Bar.beans’?
>
> I don't believe so. So long as you don't rebind the "alias" or the 
> original, you should be fine.

Okay, thank you.

-- 
 \  “I am too firm in my consciousness of the marvelous to be ever |
  `\   fascinated by the mere supernatural …” —Joseph Conrad, _The |
_o__) Shadow-Line_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting subsequences composed of the same character

2011-03-31 Thread MRAB

On 01/04/2011 01:43, candide wrote:

Suppose you have a string, for instance

"pyyythhooonnn ---> "

and you search for the subquences composed of the same character, here
you get :

'yyy', 'hh', 'ooo', 'nnn', '---', ''

It's not difficult to write a Python code that solves the problem, for
instance :


[snip]


I should confess that this code is rather cumbersome so I was looking
for an alternative. I imagine that a regular expressions approach could
provide a better method. Does a such code exist ? Note that the string
is not restricted to the ascii charset.


>>> import re
>>> re.findall(r"((.)\2+)", s)
[('yyy', 'y'), ('hh', 'h'), ('ooo', 'o'), ('nnn', 'n'), ('---', '-'), 
('', '+')]

>>> [m[0] for m in re.findall(r"((.)\2+)", s)]
['yyy', 'hh', 'ooo', 'nnn', '---', '']
--
http://mail.python.org/mailman/listinfo/python-list


Re: a basic bytecode to machine code compiler

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 5:52 PM, Terry Reedy  wrote:

> On 3/31/2011 6:33 PM, Rouslan Korneychuk wrote:
>
>> I was looking at the list of bytecode instructions that Python uses and
>> I noticed how much it looked like assembly. So I figured it can't be to
>> hard to convert this to actual machine code, to get at least a small
>> boost in speed.
>>
>> And so I whipped up a proof of concept, available at
>> https://github.com/Rouslan/nativecompile
>>
>> I'm aware that PyPy already has a working JIT compiler, but I figure it
>> will be a long time before they have a version of Python that is ready
>> for everybody to use, so this could be useful in the mean time.
>>
>
> I believe PyPy folk think it ready now, at least for some uses. Speedwise,
> it is more or less is now comparable to CPython, winning some benchmarks,
> losing others.
> ...
>
>  What do people think? Would I be wasting my time going further with this?
>>
>
> Depends on whether your goal is personal (learning, fun, use) or usefulness
> to others. For the latter, you *might* do better to help with an existing
> project, such as Cython or Dufour's ShedSkin.


Nuitka is also relevant, as is Pyrex (Pyrex being pretty similar to Cython).

Pypy's getting pretty stable now, as long as you don't demand too much of C
extension modules or ctypes.  For pure python code, I'm finding Pypy quite
nice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting subsequences composed of the same character

2011-03-31 Thread Roy Smith
In article <4d952008$0$3943$426a7...@news.free.fr>,
 candide  wrote:

> Suppose you have a string, for instance
> 
> "pyyythhooonnn ---> "
> 
> and you search for the subquences composed of the same character, here 
> you get :
> 
> 'yyy', 'hh', 'ooo', 'nnn', '---', ''

I got the following. It's O(n) (with the minor exception that the string 
addition isn't, but that's trivial to fix, and in practice, the bunches 
are short enough it hardly matters).

#!/usr/bin/env python   


s = "pyyythhooonnn ---> "
answer = ['yyy', 'hh', 'ooo', 'nnn', '---', '']

last = None
bunches = []
bunch = ''
for c in s:
if c == last:
bunch += c
else:
if bunch:
bunches.append(bunch)
bunch = c
last = c
bunches.append(bunch)

multiples = [bunch for bunch in bunches if len(bunch) > 1]
print multiples
assert(multiples == answer)


[eagerly awaiting a PEP for collections.bunch and 
collections.frozenbunch]
-- 
http://mail.python.org/mailman/listinfo/python-list


A problem about ipython

2011-03-31 Thread Vincent Ren
Hey, everyone, I'm trying to use ipython recently. It's very nice,
however, when I run this(from Programming Python 3rd) in ipython, I'll
get a NameError:


In [1]: import settime, timer, set

In [2]: import profile

In [3]: profile.run('timer.test(100, settime.setops, set.Set)')
---
NameError Traceback (most recent call
last)

/home/vincent/hacking/python/ in ()

/usr/lib/python2.6/profile.pyc in run(statement, filename, sort)
 68 prof = Profile()
 69 try:
---> 70 prof = prof.run(statement)
 71 except SystemExit:
 72 pass

/usr/lib/python2.6/profile.pyc in run(self, cmd)
454 import __main__
455 dict = __main__.__dict__
--> 456 return self.runctx(cmd, dict, dict)
457
458 def runctx(self, cmd, globals, locals):

/usr/lib/python2.6/profile.pyc in runctx(self, cmd, globals, locals)
460 sys.setprofile(self.dispatcher)
461 try:
--> 462 exec cmd in globals, locals
463 finally:
464 sys.setprofile(None)

/usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in ()

NameError: name 'timer' is not defined



But when I use normal python shell, it works well

>>> import settime, timer, set
>>> import profile
>>> profile.run('timer.test(100, settime.setops, set.Set)')
^P^P 675906 function calls in 16.961 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall
filename:lineno(function)
   1185001.1440.0001.1440.000 :0(append)
20.0000.0000.0000.000 :0(clock)
  5000.0080.0000.0080.000 :0(range)
10.0040.0040.0040.004 :0(setprofile)
10.0000.000   16.957   16.957 :1()
00.000 0.000  profile:0(profiler)
10.0000.000   16.961   16.961 profile:
0(timer.test(100, settime.setops, set.Set))
 15000.3800.0002.5040.002 set.py:13(union)
 34000.0760.0002.6320.001 set.py:2(__init__)
 34001.6200.0002.5560.001 set.py:20(concat)
   5440005.9400.0005.9400.000 set.py:26(__getitem__)
 15000.0600.000   14.0410.009 set.py:27(__and__)
 15000.0600.0002.5640.002 set.py:28(__or__)
 15007.5640.005   13.9810.009 set.py:6(intersect)
  1000.1000.001   16.9530.170 settime.py:4(setops)
10.0040.004   16.957   16.957 timer.py:1(test)



What's going wrong here?


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


Re: Extracting subsequences composed of the same character

2011-03-31 Thread Tim Chase

On 03/31/2011 07:43 PM, candide wrote:

Suppose you have a string, for instance

"pyyythhooonnn --->  "

and you search for the subquences composed of the same character, here
you get :

'yyy', 'hh', 'ooo', 'nnn', '---', ''


>>> import re
>>> s = "pyyythhooonnn ---> "
>>> [m.group(0) for m in re.finditer(r"(.)\1+", s)]
['yyy', 'hh', 'ooo', 'nnn', '---', '']
>>> [(m.group(0),m.group(1)) for m in re.finditer(r"(.)\1+", s)]
[('yyy', 'y'), ('hh', 'h'), ('ooo', 'o'), ('nnn', 'n'), ('---', 
'-'), ('', '+')]


-tkc





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


Re: Extracting subsequences composed of the same character

2011-03-31 Thread Tim Chase

On 03/31/2011 07:43 PM, candide wrote:

"pyyythhooonnn --->  "

and you search for the subquences composed of the same character, here
you get :

'yyy', 'hh', 'ooo', 'nnn', '---', ''


Or, if you want to do it with itertools instead of the "re" module:

>>> s = "pyyythhooonnn ---> "
>>> from itertools import groupby
>>> [c*length for c, length in ((k, len(list(g))) for k, g in 
groupby(s)) if length > 1]

['yyy', 'hh', 'ooo', 'nnn', '---', '']


-tkc


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


Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Raymond Hettinger
On Mar 31, 3:14 pm, Ben Finney  wrote:
> Howdy all,
>
> I want to inherit from a class, and define aliases for many of its
> attributes. How can I refer to “the attribute that will be available by
> name ‘spam’ once this class is defined”?
>
>     class Foo(object):
>         def spam(self):
>             pass
>
>         def eggs(self):
>             pass
>
>     class Bar(Foo):
>         beans = Foo.spam
>         mash = Foo.eggs
>
> Is that the right way to do it?

For methods, that will work just fine.  For attributes, you will need
to make @property accessors that get and set the underlying attribute.


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


Re: FBI wants public help solving encrypted notes from murder mystery

2011-03-31 Thread haha doh
On Mar 31, 3:15 pm, Joe Snodgrass  wrote:
> On Mar 30, 10:18 pm, "Stretto"  wrote:
>
>
>
>
>
> > "Joe Snodgrass"  wrote in message
>
> >news:c37e8e0b-a825-4ac5-9886-8828ab1fa...@x8g2000prh.googlegroups.com...
>
> > > FBI cryptanalysis hasn’t decrypted notes from 1999 murder mystery
>
> > >http://tinyurl.com/4d56zsz
>
> > > The FBI is seeking the public's help in breaking the encrypted code
> > > found in two notes discovered on the body of a murdered man in 1999.
>
> > > The FBI says that officers in St. Louis, Missouri discovered the body
> > > of 41-year-old Ricky McCormick on June 30, 1999 in a field and the
> > > clues regarding the homicide were two encrypted notes found in the
> > > victim's pants pockets.
>
> > > The FBI says that despite extensive work by its Cryptanalysis and
> > > Racketeering Records Unit (CRRU), and the American Cryptogram
> > > Association, the meanings of those two coded notes remain a mystery
> > > and McCormick's murderer has never been found. One has to wonder
> > > though, if the FBI can't figure this out, who can? But I digress.
>
> > > From the FBI: "The more than 30 lines of coded material use a
> > > maddening variety of letters, numbers, dashes, and parentheses.
> > > McCormick was a high school dropout, but he was able to read and write
> > > and was said to be 'street smart.' According to members of his family,
> > > McCormick had used such encrypted notes since he was a boy, but
> > > apparently no one in his family knows how to decipher the codes, and
> > > it's unknown whether anyone besides McCormick could translate his
> > > secret language. Investigators believe the notes in McCormick's
> > > pockets were written up to three days before his death."
>
> > > "Standard routes of cryptanalysis seem to have hit brick walls," said
> > > CRRU chief Dan Olson in a statement. To move the case forward,
> > > examiners need another sample of McCormick's coded system-or a similar
> > > one-that might offer context to the mystery notes or allow valuable
> > > comparisons to be made. Or, short of new evidence, Olson said, "Maybe
> > > someone with a fresh set of eyes might come up with a brilliant new
> > > idea."
>
> > > The FBI says it has always relied on public tips and other assistance
> > > to solve crimes though breaking a code may represent a special
> > > circumstance.
>
> > > For larger images of the notes go here. [LINK]
>
> > > If you have an idea how to break the code, have seen similar codes, or
> > > have any information about the Ricky McCormick case, write to CRRU at
> > > the following address:
>
> > > FBI Laboratory
> > > Cryptanalysis and Racketeering Records Unit
> > > 2501 Investigation Parkway
> > > Quantico, VA 22135
> > > Attn: Ricky McCormick Case
>
> > > There is no reward being offered, just the knowledge that you may be
> > > solving an intriguing murder mystery, the FBI stated.
>
> > No other information about the guy? It might help. If the note is of any use
> > then people and places would be in it. If that is the case then it would
> > help to know where he lived and some of the names of people he knows.
>
> > The note seems like it may not be just encrypted but a sort of
> > compression(or rather shorthand/jargon) was used. Was the guy a drug dealer?
> > It could be a list of "clients" or information about where he sold drugs(the
> > numbers look like street addresses or amounts.
>
> > If these kinda notes were so common from this guy then surely the FBI should
> > have many more?
>
> > Seems like the FBI could do more if they wanted it really solved...
>
> As to which crime was being committed, I'm going with numbers running
> or loan sharking.  There's no reason for any crook to keep any record
> of any other crime, except prostitution, where phone books come in
> handy.
>
> Thievery is not an honest business, and records of what went down,
> where and with whom can only hurt you.  Unless of course, it's a grand
> list of felonies that he was using to blackmail the participants.
>
> But I can't see gathering that much info from blackmail.  I always
> thought it involved one guy blackmailing one victim.  This would imply
> a factory scale process, and he'd need some way to lure his prey into
> the trap.
>
> Of course, that WOULD be a good way to get murdered.
This is him
http://img851.imageshack.us/i/4d93ac54b10bcimage.jpg/

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


Re: Extracting subsequences composed of the same character

2011-03-31 Thread Terry Reedy

On 3/31/2011 10:20 PM, Tim Chase wrote:

On 03/31/2011 07:43 PM, candide wrote:

"pyyythhooonnn ---> "

and you search for the subquences composed of the same character, here
you get :

'yyy', 'hh', 'ooo', 'nnn', '---', ''


Or, if you want to do it with itertools instead of the "re" module:

 >>> s = "pyyythhooonnn ---> "
 >>> from itertools import groupby
 >>> [c*length for c, length in ((k, len(list(g))) for k, g in
groupby(s)) if length > 1]
['yyy', 'hh', 'ooo', 'nnn', '---', '']


Slightly shorter:
[r for r in (''.join(g) for k, g in groupby(s)) if len(r) > 1]

--
Terry Jan Reedy

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


Re: Behaviour of subprocess.Popen, ssh and nohup I don't understand

2011-03-31 Thread Kushal Kumaran
On Fri, Apr 1, 2011 at 4:31 AM, Adriaan Renting  wrote:
> L.S.
>
> I have a problem that a background process that I'm trying to start with
> subprocess.Popen gets interrupted and starts waiting for input no matter
> what I try to do to have it continue to run. It happens when I run it
> with nohup in the background.
> I've tried to find a solution searching the internet, but found none.
> I've written a small test script that reproduces the problem and hope
> maybe here there is someone who can tell me what's going wrong. Any
> suggestions are welcome.
>
> (renting)myhost> cat test.py
> #!/usr/bin/python
> # script to test subprocess problem
> import subprocess, sys, time
>
> for f in range(3):
>  command = ["ssh", "-T", "localhost", "uptime"]
>  comm = subprocess.Popen(command, shell=False, stdin=None,
> stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
>  print  '1'
>  if comm.returncode:
>    print "error: %i" % (comm.return_code)
>  else:
>    print  '2'
>    (output, output2) = comm.communicate(input=None)
>    print output
>    print output2
>  print  '3'
>  time.sleep(3)
>
> (renting)myhost> python --version
> Python 2.5.2
>
> (renting)myhost> nohup ./test.py -O2 &
> [1] 15679
>
> (renting)myhost> 1
> 2
>  22:40:30 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00
>
> None
> 3
> 1
> 2
>
> [1]  + Suspended (tty input)         ./test.py -O2
> (renting)myhost> fg
> ./test.py -O2
>
>  22:40:35 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00
>
> None
> 3
> 1
> 2
>  22:40:56 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00
>
> None
> 3
>
> (renting)myhost>
>
> Now as you can see, it suspends on the second time through the for loop,
> until I bring it to the foreground and hit .
> What you don't see, is that I make it do this by pushing the arrow keys
> a couple of times. The same happens when I would exit the shell, despite
> it running with nohup.
> I don't need to exit to make it suspend, any combination of a few random
> keystrokes makes it do this. It seems depending on the timing though,
> during the sleep(3) it seems to ignore me, only when subprocess is
> actually running will it suspend if I generate keystrokes.
> If the ssh command is executed without -T option it suspends directly,
> so I think it's related to the ssh command. I log in with a
> public/private key pair to avoid having to enter a password.
>
> Any suggestions are welcome,
>

What operating system is this?  Try with stdin=open(os.devnull, 'rb')
to the Popen call instead.  Also, this seems to be similar:
http://stackoverflow.com/questions/1365653/calling-fgets-on-popen-of-ssh-is-flushing-the-beginning-of-stdin-of-the-cal

The "Suspended (tty input)" message means that a background process
tried to read from stdin, so got suspended.  This is part of the job
control mechanism.

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


Re: Guido rethinking removal of cmp from sort method

2011-03-31 Thread harrismh777

Steven D'Aprano wrote:

The difference between implementation and interface is
not specific to object-oriented code --


When I speak of implementation vs interface I am speaking from a 
strictly object oriented philosophy, as pedigree, from Grady Booch, whom 
I consider to be the father of Object Oriented Analysis and Design 
(Booch, OO A&D with apps, 1994). He makes this remarkable statement:
"The interface of a class is the one place where we assert all of 
the assumptions that a client may make about any instances [objects] of 
the class; the implementation encapsulates details about which no client 
may make assumptions" (Booch, p50, 1994).
The Class interface holds a "special" firmness which fosters the 
client relationship of trust and assumption, without which OOA&D is 
pointless. The interface of a Class must not change once advertised, and 
once in production. This is specific to OOA&D.
Encapsulation of the abstractions must reside within the 
implementation about which no one may make assumptions. This is also 
where all of the "cruft" (if any) resides. Cruft never resides at the 
interface, only in the encapsulation of the Class abstractions, and only 
if the Class was poorly designed.


To put my advice in MY other words, here are my two rules about Class 
interface based on Booch, but in terms that are mine, and which are way 
simpler to put into practice:


Rule 1:
Never change an advertised Class interface.

Corollary 1)a The Class interface never encapsulates cruft.

Corollary 1)b The Class implementation usually encapsulates cruft.

Corollary 1)c Only the Class implementation may be changed.


Rule 2:
If an advertised Class interface must be changed to remove cruft, 
please re-read Rule #1, and review corollaries 1)a, 1)b, and 1)c.





As an aside, but in response to your straw man argument regarding 
obscure "cruft," none of the bickering regarding this cmp issue is about 
obscure code. We are discussing one of the primary methods of one of the 
primary Class objects are the lovely heart of Python--- the list.sort(). 
This is NOT obscure. Guido arbitrarily altered the interface to one of 
the MOST important Class objects in all of the Python language. This is 
not good, and it does violate the spirit of OOA&D.


If the interface changes had been left to type promotion on integer 
divide, and the print() method, then folks would probably not be in such 
an uproar over 3x. But Guido over reached the bounds of credulity by 
altering a Class method that *many* people find useful, desirable, 
efficacious and easy... they use it and the love it (right or wrong).
The client(s) are making assumptions about the List Class interface 
and they have an OOA&D right to do so... and they are left with their 
rear-ends handing out in the breeze because their assumptions are false. 
Not good.


Kind regards,

m harris








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


Re: Guido rethinking removal of cmp from sort method

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 5:13 PM, harrismh777  wrote:
>    Corollary 1)a The Class interface never encapsulates cruft.

Provably false. Even a well-designed interface, if it is asked to deal
with a changing implementation and changing requirements, will
eventually either acquire cruft, or be found too rigid to be of use.
The only interface immune to this is the transparent interface
(effectively: "just package up the parameters in a single string and
pass it through"), which isn't really an interface at all, it just
exposes something else. In everything else, cruft is a reality that
must be dealt with.

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


Re: Guido rethinking removal of cmp from sort method

2011-03-31 Thread harrismh777

Terry Reedy wrote:

Python 3 was announced and as a mildly code breaking version at least 5
years before it came out.


I appreciate the spirit of your arguments overall, and I do not 
necessarily disagree with much of what you are saying. I would like to 
challenge you to see this from a little different perspective, if I may.


There are two distinct ways for looking at this "mild code 
breakage," and it might be good to think about how we approach changes 
in the future based on an understanding of both perspectives, and 
consideration for the clients.


In the possible perspective of the Python language developers  3x 
changes are mild (in fact, overall, probably even insignificant 
percentage-wise). Ok, we removed the cmp comparison keyword from 
list.sort(), made the print() method consistent with the rest of the 
language, and correctly promoted integer divide 1/2 to float so that the 
answer is something greater than zero! Fine. Looks like just a couple 
little changes, no big deal, stop your whining.


The perspective of the Class client is something quite different. 
They do not look at the overall percentage of Python language definition 
that has changed (tiny percentage, right) they look at the overall 
percentage of their own projects that have just "broken" and need to be 
rewritten to accommodate the disruption in the advertised Class 
interface. And to the client--  these tiny changes are magna-bodacious! 
(nobbled thinking)  You guys have changed integer divide---!  the PRINT 
print() functionality is diff e r e n t ---! and for crying out loud 
you changed   S O R T ( )   !!!


I wonder if folks like google need to do in-place sorts over lists 
very often ...?


I wonder how mnay Python scripts call the list.sort() method with 
the cmp keyword specified... ?  (could it be thousands, or millions?)
All the hoorah you guys are getting, as well all of this incessant 
bickering over cmp,  is some of the answer to these questions.


When you get ready to change an advertised Class interface in the 
future, please consider my interface rules (I gave them to Steven) and 
please take into account your client base---the ones who are making 
valid assumptions about your Class interfaces.  Its easy, and its most 
considerate.



king regards,
m harris



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