ANN: gcc-python-plugin 0.13

2014-10-01 Thread David Malcolm
gcc-python-plugin is a plugin for GCC 4.6 onwards which embeds the
CPython interpreter within GCC, allowing you to write new compiler
warnings in Python, generate code visualizations, etc.

It ships with gcc-with-cpychecker, which implements static analysis
passes for GCC aimed at finding bugs in CPython extensions.  In
particular, it can automatically detect
reference-counting errors:
  http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html

The major features in this release are:

  * gcc 4.9 compatibility

  * a major revamping to the HTML output from
gcc-with-cpychecker

More detailed information on these and details of the other changes can
be seen in the release notes at:
  http://gcc-python-plugin.readthedocs.org/en/latest/0.13.html


Tarball releases are available at:
  https://fedorahosted.org/releases/g/c/gcc-python-plugin/

Prebuilt-documentation can be seen at:
  http://gcc-python-plugin.readthedocs.org/en/latest/index.html

The project's homepage is:
  https://fedorahosted.org/gcc-python-plugin/

The plugin and checker are Free Software, licensed under the GPLv3 or
later.

Thanks to Buck Golemon, Denis Efremov, Philip Herron, and Tom Tromey for
their contributions to this release.


Enjoy!
Dave Malcolm


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

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


Re: how to parse standard algebraic notation

2014-10-01 Thread math math
On Tuesday, 30 September 2014 23:15:24 UTC+2, Gary Herron  wrote:
 On 09/30/2014 01:53 PM, math math wrote:
 
  Hi,
 
 
 
  I am trying to learn Python while solving exercises.
 
 
 
  I want to basically write a program that inputs a polynomial in standard 
  algebraic notation and outputs its derivative.
 
 
 
  I know that I need to get the exponent somehow, but I am not sure how to 
  accomplish this in python (3.3)
 
 
 
  Do you have any ideas or suggestions? I don't want to use existing modules 
  as this is meant to be a didactic experience.
 
 
 
  Regards
 
 
 
 This depends on things you have not yet told us.
 
 
 
 In particular -- what standard algebraic notation?  For x-squared: 
 
 x**2 ?  or perhaps  x^2 ?  or something else like some Unicode 
 
 characters or HTML to get a small superscript 2 above an x.
 
 
 
 Once you give an example of what your input looks like, we can start 
 
 hashing out how to read it.
 
 
 
 Gary Herron
 
 
 
 -- 
 
 Dr. Gary Herron
 
 Department of Computer Science
 
 DigiPen Institute of Technology
 
 (425) 895-4418

Thanks Gary (and Chris),

I should have sent a sample expression indeed.

What would be a good starting strategy for writing a program to take the 
derivative of a polynomial expression, such as this below?:
x**3 + x**2 + x + 1

I am a bit confused about my overall strategy. Should one be writing a parser 
class to split the input on operators and then on the double asterisks? Are 
there more clever ways? Or is this something one should solve using 
mathematical formulas instead of parsing the characters?

I just wonder how a seasoned Pythonian would go about a problem like this 
without using a ready-made derivative function from some module.

Regards,
Felix
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python code in presentations

2014-10-01 Thread Glenn Hutchings
On Tuesday, 30 September 2014 12:51:00 UTC+1, Jean-Michel Pichavant  wrote:
 I'm currently writing a presentation to help my co-workers ramp up on new 
 features of our tool (written in python (2.7)).
 
 I have some difficulties presenting code in an efficient way (with some basic 
 syntax highlights). I need to be catchy about the code I'm presenting 
 otherwise the presentation will fail and I would be better saying to my 
 co-workers RTFM, cause there is a manual.

A good option is to use reStructuredText and the rst2s5 converter 
(http://docutils.sourceforge.net/docs/user/slide-shows.html).  It can do syntax 
highlighting of python, and produces a slide show you display in a browser.  An 
example of what you can produce is at http://farmdev.com/talks/unicode.

Glenn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to parse standard algebraic notation

2014-10-01 Thread Mark Lawrence

On 01/10/2014 08:01, math math wrote:

[mega-snip]

You are far more likely to get answers if you access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Thoughts on python classes to represent an ebook reader

2014-10-01 Thread math math
Hi,

I hope there are people here with strong OOP experience.

Which classes would an object-oriented python programmer create for the design 
of a e-book reader for example? I am not really interested in the code, just 
the OOP classes that would come to one's mind for a task like this.

It should allow users to buy new e-books, view their list of purchased books 
and read the books.

I have made an attempt of class diagram here http://imgur.com/9TR2Tlm; but I 
would be really glad to hear other opinions. I have not used any inheritance 
for example. I didn't know exactly where it would be handy and I also dont know 
if these classes are theoretically a good basis at all...

Thanks a lot for comments/feedback.
Felix



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


Re: Weird SSL problem

2014-10-01 Thread Roland Hedberg

30 sep 2014 kl. 00:55 skrev Ned Deily n...@acm.org:

 In article cd8f39d9-acd9-4d6e-9aac-dbcdf607f...@adm.umu.se,
 Roland Hedberg roland.hedb...@adm.umu.se wrote:
 
 Hi!
 
 I¹m trying to access 
 https://stsadweb.one.microsoft.com/adfs/.well-known/openid-configuration
 
 Doing it the simplest way I get the following:
 
 import urllib
 f = 
 urllib.urlopen(https://stsadweb.one.microsoft.com/adfs/.well-known/openid
 -configuration)
 Traceback (most recent call last):
  File stdin, line 1, in module
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py,
   line 87, in urlopen
return opener.open(url)
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py,
   line 208, in open
return getattr(self, name)(url)
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py,
   line 437, in open_https
h.endheaders(data)
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py
  , line 969, in endheaders
self._send_output(message_body)
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py
  , line 829, in _send_output
self.send(msg)
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py
  , line 791, in send
self.connect()
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py
  , line 1176, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py, 
  line 387, in wrap_socket
ciphers=ciphers)
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py, 
  line 143, in __init__
self.do_handshake()
  File 
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py, 
  line 305, in do_handshake
self._sslobj.do_handshake()
 IOError: [Errno socket error] [Errno 54] Connection reset by peer
 import ssl
 ssl.OPENSSL_VERSION
 ¹OpenSSL 0.9.8za 5 Jun 2014'
 
 Now, using Safari, or curl for that matter, from the same machine works 
 without a hitch.
 
 The URL above is also the only URL I¹ve encountered this problem with.
 
 Anyone got an idea ?
 
 I believe the problem is that the connection is protected by a 
 multi-hostname server certificate and Python 2's urllib (and underlying 
 httplib and ssl modules) do not support SNI extensions to TLS.  The 
 request above works fine with Python 3 (which has supported client-side 
 SNI since Python 3.2).  See http://bugs.python.org/issue5639 for more 
 discussion of the matter.  If Python 3 is not an option for you, the 
 requests package available via PyPI should help.

You’re absolutely correct in that it’s a SNI problem.
Python 3 is not an option and I was already using requests obviously missing 
something.
Ah, had to install some extra libraries.

— Roland

”Being able to think like a child is an important attribute of being an adult” 
- Eddie Izzard

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


Re: how to parse standard algebraic notation

2014-10-01 Thread Chris Angelico
On Wed, Oct 1, 2014 at 5:01 PM, math math mathemati...@gmail.com wrote:
 What would be a good starting strategy for writing a program to take the 
 derivative of a polynomial expression, such as this below?:
 x**3 + x**2 + x + 1

 I am a bit confused about my overall strategy. Should one be writing a parser 
 class to split the input on operators and then on the double asterisks? Are 
 there more clever ways? Or is this something one should solve using 
 mathematical formulas instead of parsing the characters?

 I just wonder how a seasoned Pythonian would go about a problem like this 
 without using a ready-made derivative function from some module.

Well, let's see. Are you planning to use exact Python syntax
everywhere? For instance, will you use asterisks for multiplication
(5*x**3 + 2*x**2 - 5*x + 1)? If so, you could make use of the
ast.parse() module to do some of the work for you. Otherwise, you'll
have to start by writing up a grammar: exactly what is and isn't
allowed? Then write a parser, and see how things go from there.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on python classes to represent an ebook reader

2014-10-01 Thread Wolfgang Maier

On 01.10.2014 10:14, math math wrote:

Hi,

I hope there are people here with strong OOP experience.

Which classes would an object-oriented python programmer create for the design 
of a e-book reader for example? I am not really interested in the code, just 
the OOP classes that would come to one's mind for a task like this.

It should allow users to buy new e-books, view their list of purchased books 
and read the books.

I have made an attempt of class diagram here http://imgur.com/9TR2Tlm; but I 
would be really glad to hear other opinions. I have not used any inheritance for example. 
I didn't know exactly where it would be handy and I also dont know if these classes are 
theoretically a good basis at all...

Thanks a lot for comments/feedback.
Felix



As it happens, the very popular Calibre ebook software is written in 
Python. So, I guess, getting (https://github.com/kovidgoyal/calibre) and 
looking at its source code should give you a good start.


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


Re: SNI support in python 2.7 for Locust load tests

2014-10-01 Thread Reddy
Hi,

 Reddy  writes:
  ...
  I'm trying to use locust (http://locust.io/) to run load test of one site 
  we're developing. Everything was running nice and smooth until we switch 
  the servers to use SNI. SNI is not officially supported in python 2.7.5

 you have two options:
 
 Python 2.7.9 implements PEP 466 Network Security Enhancements for
 Python 2.7.x including TLS 1.1, 1.2 and SNI support. 2.7.9 will be
 released shortly. You could try the 2.7 branch from hg.python.org.
 
 Use PyOpenSSL instead of Python's ssl module. It supports SNI, too.

 A recent post in this list regarding missing SNI support in Python 2.x
 got as a suggestion to use the backports.ssl package on PyPI.

Thanks Christian and Dieter for your prompt responses!
I tried yesterday with Python built from 
https://hg.python.org/cpython/archive/9b4673d7b046.tar.gz. I also do use 
pyOpenSSL as described at http://stackoverflow.com/a/19477363 so I used pip to 
install pyOpenSSL, ndg-httpsclient and pyasn1 as well as patched locust startup 
file with the following:

from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()

I also tried adding the following:
from functools import partial
ssl.wrap_socket = partial(ssl.wrap_socket, ssl_version=ssl.PROTOCOL_TLSv1)

Finally, I've just tried with:
/usr/local/bin/pip2.7 install backports.ssl

and patching the lucust file with:

import backports.ssl as ssl
import backports.ssl.monkey as monkey
import requests
monkey.patch()

I've also added verify=False to my locust test scripts to disable certificate 
verification according to http://docs.locust.io/en/latest/api.html

...And I still get exactly the same error:

[2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File 
build/bdist.linux-x86_64/egg/OpenSSL/SSL.py, line 977, in sendall
[2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File 
build/bdist.linux-x86_64/egg/OpenSSL/SSL.py, line 849, in _raise_ssl_error
[2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: OpenSSL.SSL
[2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: .
[2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: WantWriteError

Now I'm starting to think it's something else than SNI, but all those scripts 
were working nice before and the only change done was turning on the SNI on 
tested servers... 

Any idea what my actually cause this WantWriteError?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python code in presentations

2014-10-01 Thread Wolfgang Keller
 Right now the method I'm using is write the code in notepad++, use a
 plugin (NppExport) to copy paste code into powerpoint. After using it
 a little bit, I'm really not satisfied with this method, it's
 expensive and all this copy paste stuff is driving me crazy. Not to
 mention that the syntax highlight from notepads renders like crap in
 powerpoint.
 
 I wonder if some people in this list who have successfully presented
 python code have some tips about doing the proper way. Ned's
 presentations for pycons are to me one example of successful code
 presentation:
   - the layout is simple
   - the code and code output are clearly identified
   - a line of code can be highlighted while presenting

LyX and Beamer.

Sincerely,

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


How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
I have a dictionary as follows:-

{
u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', 
conv=6834.374834509803, Description=u'Starter Amps'), 
u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'LeisureVolts', 
conv=29.01374215995874, Description=u'Leisure Volts'),
u'RudderPos': Row(id=6, ain=u'AIN5', name=u'RudderPos', conv=0.028125, 
Description=u'Rudder Position'),
u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', 
conv=32.727273081945, Description=u'Leisure Amps'),
u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', 
conv=28.94469628911757, Description=u'Starter Volts')
}

I want to output a menu to a user comprising some parts of the
dictionary (ain and Description) sorted by ain.

Is there some incantation of sorted() that will do what I want?  I
can't quite fathom out the 'key=' parameter needed to sort it by the
tuple item.  Maybe I need a cmp= ?

E.g. I want to do something like:-

for meas in sorted(adc.cfg, key=???):
print(adc.cfg[meas].ain, adc.cfg[meas].Description)

What's needed in the ???

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JSON-encoding very long iterators

2014-10-01 Thread Alfred Morgan
On Monday, September 29, 2014 7:10:18 PM UTC-7, Ian wrote:
 This would cause things that aren't lists to be encoded as lists.
 Sometimes that may be desirable, but in general if e.g. a file object
 sneaks its way into your JSON encode call, it is more likely correct
 to raise an error than to silently encode the file as if it were a
 list of strings.  So it should not be the default behavior. That said,
 it sounds like it could be made easier to enable streaming from
 iterators as an option for those cases where it's desired.

I added a stream flag (off by default) and also added file streaming (thanks 
for the idea).

https://github.com/Zectbumo/cpython/compare/2.7

What do you think now?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Peter Otten
c...@isbd.net wrote:

 I have a dictionary as follows:-
 
 {
 u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1',
 conv=6834.374834509803, Description=u'Starter Amps'), u'LeisureVolts':
 Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874,
 Description=u'Leisure Volts'), u'RudderPos': Row(id=6, ain=u'AIN5',
 name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'), u'xx':
 Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
 u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1',
 conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts':
 Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757,
 Description=u'Starter Volts') }
 
 I want to output a menu to a user comprising some parts of the
 dictionary (ain and Description) sorted by ain.
 
 Is there some incantation of sorted() that will do what I want?  I
 can't quite fathom out the 'key=' parameter needed to sort it by the
 tuple item.  Maybe I need a cmp= ?
 
 E.g. I want to do something like:-
 
 for meas in sorted(adc.cfg, key=???):
 print(adc.cfg[meas].ain, adc.cfg[meas].Description)
 
 What's needed in the ???

for meas in sorted(adc.cfg, key=lambda key: adc.cfg[key].ain):
print(adc.cfg[meas].ain, adc.cfg[meas].Description)

or simpler

for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain))
print(row.ain, row.Description)

or even

for row in sorted(
map(operator.attrgetter(ain, Description), adc.cfg.values())):
print(*row)

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


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Mark Lawrence

On 01/10/2014 10:58, c...@isbd.net wrote:

I have a dictionary as follows:-

{
u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', 
conv=6834.374834509803, Description=u'Starter Amps'),
u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'LeisureVolts', 
conv=29.01374215995874, Description=u'Leisure Volts'),
u'RudderPos': Row(id=6, ain=u'AIN5', name=u'RudderPos', conv=0.028125, 
Description=u'Rudder Position'),
u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', 
conv=32.727273081945, Description=u'Leisure Amps'),
u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', 
conv=28.94469628911757, Description=u'Starter Volts')
}

I want to output a menu to a user comprising some parts of the
dictionary (ain and Description) sorted by ain.

Is there some incantation of sorted() that will do what I want?  I
can't quite fathom out the 'key=' parameter needed to sort it by the
tuple item.  Maybe I need a cmp= ?

E.g. I want to do something like:-

 for meas in sorted(adc.cfg, key=???):
 print(adc.cfg[meas].ain, adc.cfg[meas].Description)

What's needed in the ???



IIRC one method involves using itemgetter from 
https://docs.python.org/3/library/operator.html#module-operator


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Joel Goldstick
On Wed, Oct 1, 2014 at 5:58 AM,  c...@isbd.net wrote:
 I have a dictionary as follows:-

 {
 u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', 
 conv=6834.374834509803, Description=u'Starter Amps'),
 u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'LeisureVolts', 
 conv=29.01374215995874, Description=u'Leisure Volts'),
 u'RudderPos': Row(id=6, ain=u'AIN5', name=u'RudderPos', conv=0.028125, 
 Description=u'Rudder Position'),
 u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
 u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', 
 conv=32.727273081945, Description=u'Leisure Amps'),
 u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', 
 conv=28.94469628911757, Description=u'Starter Volts')
 }

Is Row a function?  Or do you have a key with a tuple as the value?

 I want to output a menu to a user comprising some parts of the
 dictionary (ain and Description) sorted by ain.

 Is there some incantation of sorted() that will do what I want?  I
 can't quite fathom out the 'key=' parameter needed to sort it by the
 tuple item.  Maybe I need a cmp= ?

 E.g. I want to do something like:-

 for meas in sorted(adc.cfg, key=???):
 print(adc.cfg[meas].ain, adc.cfg[meas].Description)

 What's needed in the ???

 --
 Chris Green
 ·

You might read here:
http://www.pythoncentral.io/how-to-sort-python-dictionaries-by-key-or-value/
 --
 https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
Peter Otten __pete...@web.de wrote:
 c...@isbd.net wrote:
 
  I have a dictionary as follows:-
  
  {
  u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1',
  conv=6834.374834509803, Description=u'Starter Amps'), u'LeisureVolts':
  Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874,
  Description=u'Leisure Volts'), u'RudderPos': Row(id=6, ain=u'AIN5',
  name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'), u'xx':
  Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
  u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1',
  conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts':
  Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757,
  Description=u'Starter Volts') }
  
  I want to output a menu to a user comprising some parts of the
  dictionary (ain and Description) sorted by ain.
  
  Is there some incantation of sorted() that will do what I want?  I
  can't quite fathom out the 'key=' parameter needed to sort it by the
  tuple item.  Maybe I need a cmp= ?
  
  E.g. I want to do something like:-
  
  for meas in sorted(adc.cfg, key=???):
  print(adc.cfg[meas].ain, adc.cfg[meas].Description)
  
  What's needed in the ???
 
 for meas in sorted(adc.cfg, key=lambda key: adc.cfg[key].ain):
 print(adc.cfg[meas].ain, adc.cfg[meas].Description)
 
Brilliant, worked perfectly, thank you.  The bit I didn't understamd was
that 'lambda' bit, but I just looked it up and I'm a bit clearer now.

 or simpler
 
 for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain))
 print(row.ain, row.Description)
 
I tried this, I got:-

Traceback (most recent call last):
  File /home/chris/bin/calibrate.py, line 24, in module
  for meas in sorted(adc.cfg.values,
  key=operator.attrgetter(ain)):
  NameError: name 'operator' is not defined
I must admit that it's the bits like 'operator' in the parameters that
I can't really understand where they come from.


 or even
 
 for row in sorted(
 map(operator.attrgetter(ain, Description), adc.cfg.values())):
 print(*row)
 

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Joel Goldstick
On Wed, Oct 1, 2014 at 6:45 AM,  c...@isbd.net wrote:
 Peter Otten __pete...@web.de wrote:
 c...@isbd.net wrote:

  I have a dictionary as follows:-
 
  {
  u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1',
  conv=6834.374834509803, Description=u'Starter Amps'), u'LeisureVolts':
  Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874,
  Description=u'Leisure Volts'), u'RudderPos': Row(id=6, ain=u'AIN5',
  name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'), u'xx':
  Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
  u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1',
  conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts':
  Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757,
  Description=u'Starter Volts') }
 
  I want to output a menu to a user comprising some parts of the
  dictionary (ain and Description) sorted by ain.
 
  Is there some incantation of sorted() that will do what I want?  I
  can't quite fathom out the 'key=' parameter needed to sort it by the
  tuple item.  Maybe I need a cmp= ?
 
  E.g. I want to do something like:-
 
  for meas in sorted(adc.cfg, key=???):
  print(adc.cfg[meas].ain, adc.cfg[meas].Description)
 
  What's needed in the ???

 for meas in sorted(adc.cfg, key=lambda key: adc.cfg[key].ain):
 print(adc.cfg[meas].ain, adc.cfg[meas].Description)

 Brilliant, worked perfectly, thank you.  The bit I didn't understamd was
 that 'lambda' bit, but I just looked it up and I'm a bit clearer now.

 or simpler

 for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain))
 print(row.ain, row.Description)

 I tried this, I got:-

 Traceback (most recent call last):
   File /home/chris/bin/calibrate.py, line 24, in module
   for meas in sorted(adc.cfg.values,
   key=operator.attrgetter(ain)):
   NameError: name 'operator' is not defined
 I must admit that it's the bits like 'operator' in the parameters that
 I can't really understand where they come from.


operator is a module. See
https://docs.python.org/2/library/operator.html#module-operator

 or even

 for row in sorted(
 map(operator.attrgetter(ain, Description), adc.cfg.values())):
 print(*row)


 --
 Chris Green
 ·
 --
 https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Peter Otten
c...@isbd.net wrote:

 Peter Otten __pete...@web.de wrote:
 c...@isbd.net wrote:
 
  I have a dictionary as follows:-
  
  {
  u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1',
  conv=6834.374834509803, Description=u'Starter Amps'), u'LeisureVolts':
  Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874,
  Description=u'Leisure Volts'), u'RudderPos': Row(id=6, ain=u'AIN5',
  name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'),
  u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125,
  Description=u''), u'LeisureAmps1': Row(id=3, ain=u'AIN2',
  name=u'LeisureAmps1', conv=32.727273081945, Description=u'Leisure
  Amps'), u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts',
  conv=28.94469628911757, Description=u'Starter Volts') }
  
  I want to output a menu to a user comprising some parts of the
  dictionary (ain and Description) sorted by ain.
  
  Is there some incantation of sorted() that will do what I want?  I
  can't quite fathom out the 'key=' parameter needed to sort it by the
  tuple item.  Maybe I need a cmp= ?
  
  E.g. I want to do something like:-
  
  for meas in sorted(adc.cfg, key=???):
  print(adc.cfg[meas].ain, adc.cfg[meas].Description)
  
  What's needed in the ???
 
 for meas in sorted(adc.cfg, key=lambda key: adc.cfg[key].ain):
 print(adc.cfg[meas].ain, adc.cfg[meas].Description)
 
 Brilliant, worked perfectly, thank you.  The bit I didn't understamd was
 that 'lambda' bit, but I just looked it up and I'm a bit clearer now.

`lambda` is just a fancy way to define a function inline. With a normal 
`def` it would be

def get_ain(key):
return adc.cfg[key].ain

or meas in sorted(adc.cfg, key=get_ain):
   print(adc.cfg[meas].ain, adc.cfg[meas].Description)

 
 or simpler
 
 for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain))
 print(row.ain, row.Description)
 
 I tried this, I got:-
 
 Traceback (most recent call last):
   File /home/chris/bin/calibrate.py, line 24, in module
   for meas in sorted(adc.cfg.values,
   key=operator.attrgetter(ain)):
   NameError: name 'operator' is not defined
 I must admit that it's the bits like 'operator' in the parameters that
 I can't really understand where they come from.

As Joel says, operator is a module. To use it add

import operator

at the beginning of your module. To check if you've really understood the 
lambda you can try to replace the operator.attrgetter(ain) in

 for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain)):

with 

for row in sorted(adc.cfg.values(), key=lambda ...):

 or even
 
 for row in sorted(
 map(operator.attrgetter(ain, Description),
 adc.cfg.values())):
 print(*row)


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


Re: SNI support in python 2.7 for Locust load tests

2014-10-01 Thread Reddy
Hi,

  Reddy  writes:
   ...
   I'm trying to use locust (http://locust.io/) to run load test of one site 
   we're developing. Everything was running nice and smooth until we switch 
   the servers to use SNI. SNI is not officially supported in python 2.7.5
 
  you have two options:
  
  Python 2.7.9 implements PEP 466 Network Security Enhancements for
  Python 2.7.x including TLS 1.1, 1.2 and SNI support. 2.7.9 will be
  released shortly. You could try the 2.7 branch from hg.python.org.
  
  Use PyOpenSSL instead of Python's ssl module. It supports SNI, too.
 
  A recent post in this list regarding missing SNI support in Python 2.x
  got as a suggestion to use the backports.ssl package on PyPI.
 
 Thanks Christian and Dieter for your prompt responses!
 I tried yesterday with Python built from 
 https://hg.python.org/cpython/archive/9b4673d7b046.tar.gz. I also do use 
 pyOpenSSL as described at http://stackoverflow.com/a/19477363 so I used pip 
 to install pyOpenSSL, ndg-httpsclient and pyasn1 as well as patched locust 
 startup file with the following:
 
 from urllib3.contrib import pyopenssl
 pyopenssl.inject_into_urllib3()
 
 I also tried adding the following:
 from functools import partial
 ssl.wrap_socket = partial(ssl.wrap_socket, ssl_version=ssl.PROTOCOL_TLSv1)
 
 Finally, I've just tried with:
 /usr/local/bin/pip2.7 install backports.ssl
 
 and patching the lucust file with:
 
 import backports.ssl as ssl
 import backports.ssl.monkey as monkey
 import requests
 monkey.patch()
 
 I've also added verify=False to my locust test scripts to disable certificate 
 verification according to http://docs.locust.io/en/latest/api.html
 
 ...And I still get exactly the same error:
 
 [2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File 
 build/bdist.linux-x86_64/egg/OpenSSL/SSL.py, line 977, in sendall
 [2014-09-30 14:19:41,793] ip-x-x-x-x/ERROR/stderr: File 
 build/bdist.linux-x86_64/egg/OpenSSL/SSL.py, line 849, in _raise_ssl_error
 [2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: OpenSSL.SSL
 [2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: .
 [2014-09-30 14:19:41,794] ip-x-x-x-x/ERROR/stderr: WantWriteError
 
 Now I'm starting to think it's something else than SNI, but all those scripts 
 were working nice before and the only change done was turning on the SNI on 
 tested servers... 
 
 Any idea what my actually cause this WantWriteError?
 -- 

I think I have a clue what's wrong. By default using:
/usr/local/bin/pip2.7 install pyOpenSSL ndg-httpsclient pyasn1
gives me pyOpenSSL version 0.14. When I downgrade it to 0.13 with
/usr/local/bin/pip2.7 install pyOpenSSL==0.13
everything works nice and smooth. Interestingly, on my local Ubuntu I do have 
0.14 version of that package and it works well there...
I noticed that dowgrading it to 0.13 buids 'OpenSSL.crypto' extension and that 
does not happen when installing v. 0.14 so I guess there's simply a connection 
to openssl missing somehow there in 0.14. According to 
https://github.com/pyca/pyopenssl/releases there was a big change there:
Second, pyOpenSSL is no longer implemented in C as a collection of extension 
modules using the Python/C API. Instead, pyOpenSSL is now a pure-Python project 
with a dependency on a new project, http://github.com/pyca/cryptography, which 
provides (among other things) a cffi-based interface to OpenSSL.
but I also have the most recent version of cryptography (0.6) installed there. 
And again - it works on local Ubuntu. Weird.

I guess I'll just stick to pyOpenSSL==0.13 for the time being, unless somebody 
gives me a hint what I'm doing wrong with 0.14 :)

Br,
Reddy

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


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-10-01 Thread Peter Tomcsanyi
Ned Deily n...@acm.org wrote in message 
news:nad-d2ddcb.14070824062...@news.gmane.org...

The easiest option would be a downloadable package that would allow the
default python.org 8.5-linked _tkinter to be overridden with an 8.6
version.  There may be some news on that front in the near future.


It's October...
So I tried Python 3.4.2rc1 and it seems that it still links to Tk 8.5 on 
Mac.

Does it mean that there is no plan to link to Tk 8.6 in Python 3.4.2 on Mac?
Or is there something that can override 8.5 to 8.6 as you wrote?

In the meantime I tried MacPorts. It has Tk 8.6.1 so rotating text work 
well, but it has still a problem with semi-transparency as described here:

http://core.tcl.tk/tk/tktview?name=99b84e49ff
It has been fixed in Tk 8.6.2 that is already published for nearly a month, 
but there seems to be no uypdate on macports yet...


So I am quite frustrated that I am not able to make my Python installation 
on Mac do the same things (namely roatting text and use png files that have 
semi-transparent pixels) both on Windows and Mac.


Best regards

Peter



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


Re: how to parse standard algebraic notation

2014-10-01 Thread math math
Thanks a lot, I will give this a shot.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
Joel Goldstick joel.goldst...@gmail.com wrote:
 On Wed, Oct 1, 2014 at 6:45 AM,  c...@isbd.net wrote:
  Peter Otten __pete...@web.de wrote:
  c...@isbd.net wrote:
 
   I have a dictionary as follows:-
  
   {
   u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1',
   conv=6834.374834509803, Description=u'Starter Amps'), u'LeisureVolts':
   Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874,
   Description=u'Leisure Volts'), u'RudderPos': Row(id=6, ain=u'AIN5',
   name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'), u'xx':
   Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
   u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1',
   conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts':
   Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757,
   Description=u'Starter Volts') }
  
   I want to output a menu to a user comprising some parts of the
   dictionary (ain and Description) sorted by ain.
  
   Is there some incantation of sorted() that will do what I want?  I
   can't quite fathom out the 'key=' parameter needed to sort it by the
   tuple item.  Maybe I need a cmp= ?
  
   E.g. I want to do something like:-
  
   for meas in sorted(adc.cfg, key=???):
   print(adc.cfg[meas].ain, adc.cfg[meas].Description)
  
   What's needed in the ???
 
  for meas in sorted(adc.cfg, key=lambda key: adc.cfg[key].ain):
  print(adc.cfg[meas].ain, adc.cfg[meas].Description)
 
  Brilliant, worked perfectly, thank you.  The bit I didn't understamd was
  that 'lambda' bit, but I just looked it up and I'm a bit clearer now.
 
  or simpler
 
  for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain))
  print(row.ain, row.Description)
 
  I tried this, I got:-
 
  Traceback (most recent call last):
File /home/chris/bin/calibrate.py, line 24, in module
for meas in sorted(adc.cfg.values,
key=operator.attrgetter(ain)):
NameError: name 'operator' is not defined
  I must admit that it's the bits like 'operator' in the parameters that
  I can't really understand where they come from.
 
 
 operator is a module. See
 https://docs.python.org/2/library/operator.html#module-operator

Ah, OK, as it sort of might be a keyword I hadn't thought of that. :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to parse standard algebraic notation

2014-10-01 Thread Marco Buttu

On 01/10/2014 09:01, math math wrote:

What would be a good starting strategy for writing a program to take the 
derivative of a polynomial expression, such as this below?:
x**3 + x**2 + x + 1


You can look at sympy:

 from sympy import *
 equation = simplify(x**3 + x**2 + x + 1)
 equation
x**3 + x**2 + x + 1
 diff(equation)
3*x**2 + 2*x + 1

--
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbu...@oa-cagliari.inaf.it

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


Re: how to parse standard algebraic notation

2014-10-01 Thread Marco Buttu

On 01/10/2014 09:01, math math wrote:


What would be a good starting strategy for writing a program to take the 
derivative of a polynomial expression, such as this below?:
x**3 + x**2 + x + 1


You can look at sympy:

 from sympy import *
 equation = simplify(x**3 + x**2 + x + 1)
 equation
x**3 + x**2 + x + 1
 diff(equation)
3*x**2 + 2*x + 1

--
Marco Buttu
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
Joel Goldstick joel.goldst...@gmail.com wrote:
 On Wed, Oct 1, 2014 at 5:58 AM,  c...@isbd.net wrote:
  I have a dictionary as follows:-
 
  {
  u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', 
  conv=6834.374834509803, 
 Description=u'Starter Amps'), 
  u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'LeisureVolts', 
  conv=29.01374215995874, 
 Description=u'Leisure Volts'), 
  u'RudderPos': Row(id=6, ain=u'AIN5', name=u'RudderPos', conv=0.028125, 
 Description=u'Rudder Position'), 
  u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
  u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', 
  conv=32.727273081945, 
 Description=u'Leisure Amps'), 
  u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', 
  conv=28.94469628911757, 
 Description=u'Starter Volts') 
  }
 
 Is Row a function?  Or do you have a key with a tuple as the value?

Row is a namedtuple, the dictionary is extracted from a database with
a row factory so the namedtuple names are the column names.  It means
that if I change a column name then most things continue to work
without any code changes, and also I can refer to items in the tuple
by name of course.

I have the answer to my question in other responses.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JSON-encoding very long iterators

2014-10-01 Thread Chris Angelico
On Wed, Oct 1, 2014 at 8:13 PM, Alfred Morgan alf...@54.org wrote:
 I added a stream flag (off by default) and also added file streaming (thanks 
 for the idea).

 https://github.com/Zectbumo/cpython/compare/2.7

 What do you think now?

I think that you're adding features to Python 2.7, which isn't getting
new features. That won't be merged into trunk. Does your patch apply
to 3.x?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Restarting Python

2014-10-01 Thread Steven D'Aprano
Terry Reedy wrote:

 Python does not have 'commands'.

Terry, even experienced Python developers sometimes describe functions and
statements as commands, e.g. Use the print command to display results.
I think we can cut a beginner like Seymore a bit of slack for misusing
terminology.

-- 
Steven

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


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-10-01 Thread Kevin Walzer

On 10/1/14, 7:51 AM, Peter Tomcsanyi wrote:

Ned Deily n...@acm.org wrote in message
news:nad-d2ddcb.14070824062...@news.gmane.org...

The easiest option would be a downloadable package that would allow the
default python.org 8.5-linked _tkinter to be overridden with an 8.6
version.  There may be some news on that front in the near future.


It's October...
So I tried Python 3.4.2rc1 and it seems that it still links to Tk 8.5 on
Mac.
Does it mean that there is no plan to link to Tk 8.6 in Python 3.4.2 on
Mac?
Or is there something that can override 8.5 to 8.6 as you wrote?



The solution here is to build Python and Tcl/Tk yourself, in the 
versions you want, and then things should work just fine.



--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Restarting Python

2014-10-01 Thread Rustom Mody
On Wednesday, October 1, 2014 6:39:11 PM UTC+5:30, Steven D'Aprano wrote:
 Terry Reedy wrote:

  Python does not have 'commands'.

 Terry, even experienced Python developers sometimes describe functions and
 statements as commands, e.g. Use the print command to display results.
 I think we can cut a beginner like Seymore a bit of slack for misusing
 terminology.

Agreed in general.
However in this case I wonder... Do you even understand what is being requested?

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



Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-10-01 Thread Steven D'Aprano
Chris Angelico wrote:

 I'd agree, where trivial limits is defined by each individual item.
 Going with straight Python code is fine for huge projects with long
 config files, as long as each config entry is itself simple. You even
 get a form of #include: from otherfile import *.

I would argue the opposite.

If I have a large Python project, with big config files, then the added
complexity of moving the config data into separate files using a
non-executable format (say, JSON or INI) is minimal, and keeping the data
and code separate will pay off. But for small Python projects, with only a
few data values, keeping them separate is overkill.

So, to the Original Poster, I think that depending on the size of your
program and the amount of config data you have to deal with, there's
nothing wrong with including it directly in the module.


-- 
Steven

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


Re: Restarting Python

2014-10-01 Thread Steven D'Aprano
Seymore4Head wrote:

 Since the developers of Python decided to make Python 3 non backward
 compatible, I can't help but wonder why they don't think a command to
 restart would be a useful addition?

Possibly because it isn't a useful addition? Or maybe they just never
thought of it. But more likely the first.

Why doesn't Microsoft Office have a Restart Office command? Or Outlook? Or
Notepad? Normally to restart anything, with the exception of the operating
system, you exit/quit, then start again.

Inside the interactive interpreter, I can restart the interpreter with four
keystrokes:

- Ctrl-D 
- UP-ARROW 
- ENTER

Ctrl-D exits Python and returns me to the shell, UP-ARROW fetches the
previous command (python), and ENTER runs that command. On Windows, I
*think* you have to type Ctrl-Z ENTER instead of Ctrl-D, so that will be
five keystrokes. Either way, that's significantly faster and simpler than
using a restart function, say:

- type restart()
- ENTER

(twelve keystrokes). Even if restarting is a little harder:

- type quit()
- press ENTER
- click Start Menu  Programs  Python  Python33.exe

it's still not very hard in the big picture. So having a restart command
would be of very little benefit in the interactive interpreter. (I don't
say *no* benefit.) But it's actually a quite hard thing to do, restarting a
process from within itself. It can obviously be done, since I've seen
programs like Firefox do it, but I'm not sure how to write such a function.
I think that something like this might do the job:

- grab the current process ID;
- start a daemon process which monitors that process ID;
- exit;
- when the daemon process sees that process ID is no longer alive, 
  start up the application again;

but that glosses over a number of painful difficulties. What if the parent
terminal is no longer running? What about environment variables and command
line arguments? What happens if you are running over a remote shell like
ssh, and the link is terminated as soon as the Python process ends?

So automatically restart would be a lot of work, it would quite likely be
fragile and easily broken, and the benefit would be minimal.

But it gets worse... because restart() would also be available when running
non-interactive programs. And it isn't even clear what that should do, let
alone how to do it.

Consider a program like this:

import sys
x = 42
sys.exit()
print(Hello World)


That prints nothing, because exit() stops the program from running any
further. But what if we replace the exit() with a restart()? What would you
expect it to do?

If you expect it to restart, then continue on by printing Hello World,
then the Python interpreter would have to be completely redesigned from
scratch. All that work, just as a convenience for restarting, is not worth
it.

I note that this sort of system can actually be justified. During the Apollo
program, the landing module's computer was designed to restart when it ran
out of memory and continue on with the current calculation that had been
interrupted:

https://www.hq.nasa.gov/alsj/a11/a11.1201-pa.html

During the eight minutes that it took for the Eagle to land on the moon, the
computer restarted at least five times, including three times in one 40
second period.

http://www.doneyles.com/LM/Tales.html


But Python is a long way from a Lunar Lander, and a restart() command would
be a lot of effort for not much benefit.


-- 
Steven

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


Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-10-01 Thread Chris Angelico
On Thu, Oct 2, 2014 at 12:49 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:

 I'd agree, where trivial limits is defined by each individual item.
 Going with straight Python code is fine for huge projects with long
 config files, as long as each config entry is itself simple. You even
 get a form of #include: from otherfile import *.

 I would argue the opposite.

Welcome to design debates, where there are as many valid and
justifiable views as there are participants :)

Though I wasn't precluding small config files from being code - just
saying that I don't think size of project is a factor at all.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Clearing globals in CPython

2014-10-01 Thread Steven D'Aprano
Out of curiosity, I ran:

globals().clear()

in the interactive interpreter. It broke much more than I expected!
Built-ins were no longer available, and import stopped working.

I expected that global variables would be all lost, but built-ins would
remain, since they don't live in the global namespace. I was wrong:

 globals().clear()
 x = len([])
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'len' is not defined

The reason, I think, is that CPython has a special __builtins__ global
variable that the interpreter uses to access built-in functions. What
*appears* to be happening is that if that __builtins__ global is missing,
CPython can not access the built-ins.

(Supporting this interpretation: IronPython, like CPython, has a
__builtins__ global, and behaves the same when the globals() are cleared.
Jython, which does not have a __builtins__ global, does not.)

Well that's okay, I thought to myself, I'll just import the built-in
functions:

 from builtins import len  # use '__builtin__' in Python 2
Traceback (most recent call last):
  File stdin, line 1, in module
ImportError: __import__ not found

Oops.

So, with no built-ins available, import no longer works. That makes things
rather tricky.

Obviously the easiest way to recover is to exit the current session and
restart it, but as a challenge, can we recover from this state?


-- 
Steven

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


Re: Clearing globals in CPython

2014-10-01 Thread Chris Angelico
On Thu, Oct 2, 2014 at 2:00 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Obviously the easiest way to recover is to exit the current session and
 restart it, but as a challenge, can we recover from this state?

Oooh interesting. This is kinda like breaking out of a sandbox, and I
know there are people here who are experts at that. However... I'm not
entirely sure how to get a backtrace, when you don't have any built-in
exceptions! In Python 2, I can define an old-style class and raise
that. However, with the removal of __builtins__, Python throws a bunch
of errors about restricted mode, so I'm really not sure where to go
from there.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python code in presentations

2014-10-01 Thread Jean-Michel Pichavant
- Original Message -
 From: Wolfgang Keller felip...@gmx.net
 To: python-list@python.org
 Sent: Wednesday, 1 October, 2014 11:42:34 AM
 Subject: Re: Python code in presentations
 
  Right now the method I'm using is write the code in notepad++, use
  a
  plugin (NppExport) to copy paste code into powerpoint. After using
  it
  a little bit, I'm really not satisfied with this method, it's
  expensive and all this copy paste stuff is driving me crazy. Not to
  mention that the syntax highlight from notepads renders like crap
  in
  powerpoint.
  
  I wonder if some people in this list who have successfully
  presented
  python code have some tips about doing the proper way. Ned's
  presentations for pycons are to me one example of successful code
  presentation:
- the layout is simple
- the code and code output are clearly identified
- a line of code can be highlighted while presenting
 
 LyX and Beamer.
 
 Sincerely,
 
 Wolfgang

Thank you all for all your great suggestions.

I think I now have all I need.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to parse standard algebraic notation

2014-10-01 Thread Steven D'Aprano
math math wrote:

 Hi,
 
 I am trying to learn Python while solving exercises.
 
 I want to basically write a program that inputs a polynomial in standard
 algebraic notation and outputs its derivative.
 
 I know that I need to get the exponent somehow, but I am not sure how to
 accomplish this in python (3.3)
 
 Do you have any ideas or suggestions? I don't want to use existing modules
 as this is meant to be a didactic experience.

Code for evaluating mathematical expressions are very common, if you google
for expression parser I am sure you will find many examples. Don't limit
yourself to Python code, you can learn from code written in other languages
too, e.g. I have a Pascal programming book that develops a parser for both
polynomials and arithmetic expression. The code is fairly long, but quite
straightforward to translate into Python (and Pascal code is quite
readable.)

Look at an standard infix expression, using ^ for powers:

4*x^3 + x^2 - 5*x + 1

There are four terms:

4*x^3 
x^2 
-5*x
1

So if you replace - with +- and then split on +, you will get terms:

py expr = 4*x^3 + x^2 - 5*x + 1
py terms = expr.replace(-, +-).split(+)
py terms
['4*x^3 ', ' x^2 ', '- 5*x ', ' 1']

Strip spaces from each term:

py terms = [s.replace(' ', '') for s in terms]
py terms
['4*x^3', 'x^2', '-5*x', '1']

Unfortunately, terms can include optional parts. The coefficient is
optional, and may be just a minus sign; the power is optional. To make
processing easier, we can do this:

term = term.replace('-x', '-1*x')
if term.startswith('x'):
term = term.replace('x', '1*x')
if term.endswith('x'):
term = term.replace('x', 'x^1')

to each term, which will give us something like:

['4*x^3', '1*x^2', '-5*x^1', '1']

If a term is all digits (with an optional leading minus sign) then it is the
constant term. Otherwise, it will be of the form:

[optional minus sign][one or more digits]*x^[one or more digits]

which can now be easily parsed by splitting it up around the *, x or ^
symbols. Or use a regular expression.



-- 
Steven

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


Re: how to parse standard algebraic notation

2014-10-01 Thread Chris Angelico
On Thu, Oct 2, 2014 at 2:45 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Code for evaluating mathematical expressions are very common, if you google
 for expression parser I am sure you will find many examples. Don't limit
 yourself to Python code, you can learn from code written in other languages
 too, e.g. I have a Pascal programming book that develops a parser for both
 polynomials and arithmetic expression.

Building expression evaluators is good fun! And then you can add
specialty terms, like dice rolling.

 roll 2d6 + d6 Electric + 12 Strength
[ROLL] Rosuav rolls 2d6: 3, 6, totalling 9.
[ROLL] Rosuav rolls d6: 1 (Electric)
[ROLL] Rosuav adds a bonus of 12 (Strength)
[ROLL] For 2d6 + d6 Electric + 12 Strength, Rosuav totals: 22

The code behind that follows a fairly similar pattern to what you
describe, only it deals with dice rolls (NdM - roll N dice with M
sides each) instead of powers of x. (And it allows comments/tags.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clearing globals in CPython

2014-10-01 Thread Chris Kaynor
On Wed, Oct 1, 2014 at 9:14 AM, Chris Angelico ros...@gmail.com wrote:

 On Thu, Oct 2, 2014 at 2:00 AM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
  Obviously the easiest way to recover is to exit the current session and
  restart it, but as a challenge, can we recover from this state?

 Oooh interesting. This is kinda like breaking out of a sandbox, and I
 know there are people here who are experts at that. However... I'm not
 entirely sure how to get a backtrace, when you don't have any built-in
 exceptions! In Python 2, I can define an old-style class and raise
 that. However, with the removal of __builtins__, Python throws a bunch
 of errors about restricted mode, so I'm really not sure where to go
 from there.


I've played with it a bit, and I haven't  found any way to break it yet.

I have discovered that you cannot directly declare classes, although you
can access the type built-in (indirectly) so it might be possible to
indirectly declare a class.

It is also possible to access the types of many of the built-ins (str,
bytes, dict, set, type, object, frame, function, code, generator, int,
float at a minimum).

Note that I've been playing with Python 3.4.1.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clearing globals in CPython

2014-10-01 Thread Peter Otten
Steven D'Aprano wrote:

 Out of curiosity, I ran:
 
 globals().clear()
 
 in the interactive interpreter. It broke much more than I expected!
 Built-ins were no longer available, and import stopped working.
 
 I expected that global variables would be all lost, but built-ins would
 remain, since they don't live in the global namespace. I was wrong:
 
 globals().clear()
 x = len([])
 Traceback (most recent call last):
   File stdin, line 1, in module
 NameError: name 'len' is not defined
 
 The reason, I think, is that CPython has a special __builtins__ global
 variable that the interpreter uses to access built-in functions. What
 *appears* to be happening is that if that __builtins__ global is missing,
 CPython can not access the built-ins.
 
 (Supporting this interpretation: IronPython, like CPython, has a
 __builtins__ global, and behaves the same when the globals() are cleared.
 Jython, which does not have a __builtins__ global, does not.)
 
 Well that's okay, I thought to myself, I'll just import the built-in
 functions:
 
 from builtins import len  # use '__builtin__' in Python 2
 Traceback (most recent call last):
   File stdin, line 1, in module
 ImportError: __import__ not found
 
 Oops.
 
 So, with no built-ins available, import no longer works. That makes things
 rather tricky.
 
 Obviously the easiest way to recover is to exit the current session and
 restart it, but as a challenge, can we recover from this state?

$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type help, copyright, credits or license for more information.
 globals().clear()
 import that
Traceback (most recent call last):
  File stdin, line 1, in module
ImportError: __import__ not found
 object = 1 .__class__.__bases__[0]
 Quitter = [c for c in object.__subclasses__() if c.__name__ == 
Quitter][0]
 __builtins__ = Quitter.__call__.__globals__[__builtins__]
 import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


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


Re: Python 3.4.1 installer on Mac links Python to old Tcl/Tk

2014-10-01 Thread Ned Deily
In article m0gps5$4r5$1...@ger.gmane.org,
 Peter Tomcsanyi tomcsa...@slovanet.sk wrote:
 Ned Deily n...@acm.org wrote in message 
 news:nad-d2ddcb.14070824062...@news.gmane.org...
 It's October...
 So I tried Python 3.4.2rc1 and it seems that it still links to Tk 8.5 on 
 Mac.
 Does it mean that there is no plan to link to Tk 8.6 in Python 3.4.2 on Mac?
 Or is there something that can override 8.5 to 8.6 as you wrote?

The python.org 3.4.x series of installers will likely never change from 
linking with Tk 8.5 by default.  That would break a number of important 
third-party Python packages that supply binary distributions built for 
the python.org OS X pythons, like matplotlib.  For Python 3.5, we will 
have the opportunity to change that.  

 In the meantime I tried MacPorts. It has Tk 8.6.1 so rotating text work 
 well, but it has still a problem with semi-transparency as described here:
 http://core.tcl.tk/tk/tktview?name=99b84e49ff
 It has been fixed in Tk 8.6.2 that is already published for nearly a month, 
 but there seems to be no uypdate on macports yet...

File an update request for the tcl and tk ports on the MacPorts tracker.  
The project is usually very responsive to such requests.

https://trac.macports.org

Note that ActiveState hasn't yet released their versions of 8.6.2.

 So I am quite frustrated that I am not able to make my Python installation 
 on Mac do the same things (namely roatting text and use png files that have 
 semi-transparent pixels) both on Windows and Mac.

As Kevin Walzer points out, you *can* also build your own.  I still 
intend to provide a downloadable solution for 3.4.x and 2.7.x; I hope to 
get back to it shortly.  Sorry for the delay!

-- 
 Ned Deily,
 n...@acm.org

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


Re: Restarting Python

2014-10-01 Thread Terry Reedy

On 10/1/2014 10:47 AM, Steven D'Aprano wrote:


Inside the interactive interpreter, I can restart the interpreter with four
keystrokes:

- Ctrl-D
- UP-ARROW
- ENTER

Ctrl-D exits Python and returns me to the shell, UP-ARROW fetches the
previous command (python), and ENTER runs that command. On Windows, I
*think* you have to type Ctrl-Z ENTER instead of Ctrl-D, so that will be
five keystrokes.


For the console interpreter, this is still true even in 3.5.0a0
 ^D
  File stdin, line 1
♦
^
SyntaxError: invalid syntax

Idle now quits on ^D on all systems. ^Z (unlike other control chars) is 
rejected with an immediate error beep.


Either way, restart is a single click if one have the console or Idle 
interpreter icon pinned on the task bar.


Even this is unnecessary with Idle as it has a Restart Shell command on 
the Shell menu (hotkey ^F6).  (This is automatically invoked when 
running an edited file (F5)).



Some problems with restarting are unwinding the call stack, undoing 
what has been done, and doing something else so as to not run into the 
same problem.  We can view every raise -- except pair as a partial 
restart of some sort.  A minimal startup script something like the 
following allows a nearly global restart that addresses all three 
problems listed above.


from appmain import main, cleanup, RestartError
restart = False
while True:
  try:
main(restart)
  except RestartError as err:
cleanup()
restart = err
continue

The main and cleanup functions, switching on the restart arg, and 
possibly the class RestartError depend on the app.


--
Terry Jan Reedy


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


Re: Clearing globals in CPython

2014-10-01 Thread Mark Lawrence

On 01/10/2014 17:00, Steven D'Aprano wrote:

Out of curiosity, I ran:

globals().clear()

in the interactive interpreter. It broke much more than I expected!
Built-ins were no longer available, and import stopped working.

I expected that global variables would be all lost, but built-ins would
remain, since they don't live in the global namespace. I was wrong:


globals().clear()
x = len([])

Traceback (most recent call last):
   File stdin, line 1, in module
NameError: name 'len' is not defined

The reason, I think, is that CPython has a special __builtins__ global
variable that the interpreter uses to access built-in functions. What
*appears* to be happening is that if that __builtins__ global is missing,
CPython can not access the built-ins.

(Supporting this interpretation: IronPython, like CPython, has a
__builtins__ global, and behaves the same when the globals() are cleared.
Jython, which does not have a __builtins__ global, does not.)

Well that's okay, I thought to myself, I'll just import the built-in
functions:


from builtins import len  # use '__builtin__' in Python 2

Traceback (most recent call last):
   File stdin, line 1, in module
ImportError: __import__ not found

Oops.

So, with no built-ins available, import no longer works. That makes things
rather tricky.

Obviously the easiest way to recover is to exit the current session and
restart it, but as a challenge, can we recover from this state?




We obviously need a Restart Command.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Clearing globals in CPython

2014-10-01 Thread Terry Reedy

On 10/1/2014 12:00 PM, Steven D'Aprano wrote:

Out of curiosity, I ran:

globals().clear()

in the interactive interpreter. It broke much more than I expected!
Built-ins were no longer available, and import stopped working.


As you discovered, this reduces the interpreter to a pure syntax machine 
with no name bindings -- sort of like a high-level assembler with no 
access to a function library.



I expected that global variables would be all lost, but built-ins would
remain, since they don't live in the global namespace. ...
The reason, I think, is that CPython has a special __builtins__ global
variable that the interpreter uses to access built-in functions.


When executing statements from Shell, Idle restores __builtins__.
 globals().clear()
 print(dir())
['__builtins__']
 print(__builtins__)
long listing

The odd thing is that executing the same code from a file prints [] and 
then raises NameError: name '__builtins__' is not defined.



Well that's okay, I thought to myself, I'll just import the built-in
functions:


from builtins import len  # use '__builtin__' in Python 2

Traceback (most recent call last):
   File stdin, line 1, in module
ImportError: __import__ not found


Most keyword statements are implemented by internal functions not 
accessible from Python except through the statement syntax.  Import is 
an exception.  This is one of the hooks that allow the behavior of 
imports to be modified.  The result is like, for instance, programming 
in C with 'include' disabled.



Oops.

So, with no built-ins available, import no longer works. That makes things
rather tricky.

Obviously the easiest way to recover is to exit the current session and
restart it, but as a challenge, can we recover from this state?



--
Terry Jan Reedy

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


Re: JSON-encoding very long iterators

2014-10-01 Thread Alfred Morgan
On Wednesday, October 1, 2014 6:07:23 AM UTC-7, Chris Angelico wrote:
 On Wed, Oct 1, 2014 at 8:13 PM, Alfred Morgan wrote:
  What do you think now?
 
 I think that you're adding features to Python 2.7, which isn't getting
 new features. That won't be merged into trunk. Does your patch apply
 to 3.x?
 
 ChrisA

Thanks Chris, Yes I made changes to 2.7 because I'm not familiar with Python3 
yet. Once I get some feedback I was going to see if someone was interested in 
porting it. If not I will learn and do it myself.
The patch will not work on the 3.x code but the code is similar enough to 
easily port over.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Obscuring Python source from end users

2014-10-01 Thread Dan Stromberg
On Mon, Sep 29, 2014 at 4:47 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 norman.i...@gmail.com wrote:

 Hello list

 Python 3.4 applies.

 I have a project that involves distributing Python code to users in an
 organisation. Users do not interact directly with the Python code; they
 only know this project as an Excel add-in.

 Now, internal audit takes exception in some cases if users are able to see
 the source code.

 You have my sympathy.

Actually, I don't think this is that bad.  Companies have rules; one
simply has to learn to live with this or suffer greatly.  Some rules
are worth fighting, but this probably isn't one of them.

 So I'm wondering if anyone has clever suggestions in this regard...

 Yes. Distribute the pyc files only.

Yes, this is the way it's usually done.  Supposedly Microsoft did this
for a while, after acquiring some Python software.  In the Python 3.4
case, the pyc's should be in the __pycache__ subdirectory.

Another option would be to convert to Cython and compile (not as bad
as it sounds).  But __pycache__/*.pyc would probably be easier.
-- 
https://mail.python.org/mailman/listinfo/python-list


Function passed as an argument returns none

2014-10-01 Thread Shiva
Hi,
I am learning Python (version 3.4) strings.I have a function that takes in a
parameter and prints it out as given below.

def donuts(count):
  if count = 5:
print('Number of donuts: ',count)
  else:
print('Number of donuts: many')
return

It works fine if I call 
donuts(5)

It returns:
we have 5 DN  (as expected)

However if I do :

test(donuts(4), 'Number of donuts: 4')


where test is defined as below:

def test(got, expected):
  print('got: ', got, 'Expected:' ,expected)
  if got == expected:
prefix = ' OK '
  else:
prefix = '  X '
  print (('%s got: %s expected: %s') % (prefix, repr(got), repr(expected)))


Only 'None' gets passed on to parameter 'got' instead of the expected value
of 4.
Any idea why 'None' is getting passed even though calling the donuts(4)
alone returns the expected value?

Thanks,
Shiva.

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


Re: Function passed as an argument returns none

2014-10-01 Thread Andrew Berg
On 2014.10.01 17:37, Shiva wrote:
 Only 'None' gets passed on to parameter 'got' instead of the expected value
 of 4.
 Any idea why 'None' is getting passed even though calling the donuts(4)
 alone returns the expected value?
donuts() prints what you tell it to (Number of donuts: 5), and then returns
what you tell it to (nothing).
If you don't explicitly make a function return something, it returns None.
Whatever other logic you have in the function is irrelevant.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-01 Thread Chris Kaynor
Chris

On Wed, Oct 1, 2014 at 3:37 PM, Shiva shivaji...@yahoo.com.dmarc.invalid
wrote:

 Hi,
 I am learning Python (version 3.4) strings.I have a function that takes in
 a
 parameter and prints it out as given below.

 def donuts(count):
   if count = 5:
 print('Number of donuts: ',count)
   else:
 print('Number of donuts: many')
 return


Print actually prints the value, and does not return it.

Based off the rest of your code, you probably want this to look like
(untested):

def donuts(count):
  if count = 5:
return 'Number of donuts: {}'.format(count) # You could also use other
formatting methods here, if you prefer the printf-style %s instead.
  else:
return 'Number of donuts: many'

Which will cause donuts to return the actual string, rather than printing
it out to the TTY.

Note that this means that, if run from the interpreter as you have been
trying, the interpreter will now display Number of donuts: 4 - including
the quotes.


 It works fine if I call
 donuts(5)

 It returns:
 we have 5 DN  (as expected)

 However if I do :

 test(donuts(4), 'Number of donuts: 4')


If you do as mentioned above, donuts will then return the value, and it
will be passed into test.


 where test is defined as below:

 def test(got, expected):
   print('got: ', got, 'Expected:' ,expected)
   if got == expected:
 prefix = ' OK '
   else:
 prefix = '  X '
   print (('%s got: %s expected: %s') % (prefix, repr(got), repr(expected)))


 Only 'None' gets passed on to parameter 'got' instead of the expected value
 of 4.
 Any idea why 'None' is getting passed even though calling the donuts(4)
 alone returns the expected value?


donuts is, in fact, returning None when called alone. It merely looks like
it is returning it as, when run from the interpreter, Python prints the
repr of the return values of any non-None returns. This is known as a
REPL: read, execute, print, loop. It is quite handy for debugging.

Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JSON-encoding very long iterators

2014-10-01 Thread Chris Angelico
On Thu, Oct 2, 2014 at 8:01 AM, Alfred Morgan alf...@54.org wrote:
 On Wednesday, October 1, 2014 6:07:23 AM UTC-7, Chris Angelico wrote:
 On Wed, Oct 1, 2014 at 8:13 PM, Alfred Morgan wrote:
  What do you think now?

 I think that you're adding features to Python 2.7, which isn't getting
 new features. That won't be merged into trunk. Does your patch apply
 to 3.x?

 ChrisA

 Thanks Chris, Yes I made changes to 2.7 because I'm not familiar with Python3 
 yet. Once I get some feedback I was going to see if someone was interested in 
 porting it. If not I will learn and do it myself.
 The patch will not work on the 3.x code but the code is similar enough to 
 easily port over.

Okay. At some point, you'll have to port your patch to the latest
codebase, though, as the core devs won't want to do that work
themselves.

I recommend getting familiar enough with Python 3 to be able to see if
the patch at least makes sense. (I expect it probably will.) Try out a
vanilla 3.4 or master (3.5ish), then apply your patch, and see if the
improvement is indeed visible. Assuming it is (again, I expect it will
be; JSON isn't materially different in Python 3), you can post a 3.x
patch here, and you'll have rather more interest, I think - certainly
people like me won't be applying your 2.7 patch, as that's not
something that's ever going to actually happen.

But due to the changes of str/unicode to str/bytes in Py3, you will
find that your patch requires more than just simple tweaks. It won't
be as simple as apply the patch and fix a merge conflict; you'll
have to rethink your changes and apply them to the different codebase.
Unfortunately, that's just what happens when you start development on
2.7; there are differences in the code, and there's no getting around
them. It'll be much easier for you if you get familiar with Py3 and do
development there. :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-01 Thread Mark Lawrence

On 01/10/2014 23:37, Shiva wrote:

Hi,
I am learning Python (version 3.4) strings.I have a function that takes in a
parameter and prints it out as given below.

def donuts(count):
   if count = 5:
 print('Number of donuts: ',count)
   else:
 print('Number of donuts: many')
 return

It works fine if I call
donuts(5)

It returns:
we have 5 DN  (as expected)


It doesn't :)  As it takes the first path through the function it will 
*print* 'Number of donuts: 5' and then return None as you haven't 
specified what your function returns.




However if I do :

test(donuts(4), 'Number of donuts: 4')


where test is defined as below:

def test(got, expected):
   print('got: ', got, 'Expected:' ,expected)
   if got == expected:
 prefix = ' OK '
   else:
 prefix = '  X '
   print (('%s got: %s expected: %s') % (prefix, repr(got), repr(expected)))


Only 'None' gets passed on to parameter 'got' instead of the expected value
of 4.


Your expectations are wrong, your function makes no attempt to return 
the value you've passed in.  I'd (re)read the tutorial again and digest 
it, then have another go.



Any idea why 'None' is getting passed even though calling the donuts(4)
alone returns the expected value?


What is your expected value?  My expected value is None for a value of 4 
as you've given a return statement without specifying a value.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Function passed as an argument returns none

2014-10-01 Thread Denis McMahon
On Wed, 01 Oct 2014 22:37:13 +, Shiva wrote:

 Hi,
 I am learning Python (version 3.4) strings.I have a function that takes
 in a parameter and prints it out as given below.
 
 def donuts(count):
   if count = 5:
 print('Number of donuts: ',count)
   else:
 print('Number of donuts: many') return
 
 It works fine if I call donuts(5)
 
 It returns:

No it doesn't

 we have 5 DN  (as expected)

It doesn't return anything, it prints something out.

Printing something out from within a function is not the same as 
returning something.

Consider the following::

def nonsense( something ):
print( something is, something )
return ( 5, elephants, { monkey: peanut, baboon: 
 banana, numbers: ( 1, ), }, [ 1, 2, 3, 4, 5, 
 mouse,( -6.34565e-35, 4.765213e84, ), ], 
 None, True, False, )

print( nonsense( 10 ) is, nonsense( 10 ) )
print( nonsense( None ) is, nonsense( None ) )
print( nonsense( ( 5, \donuts\, ) ) is, nonsense( ( 5, donuts, ) ) )

The above code shows there is no automatic connection between data output 
carried out within a function and the value (if any) returned by that 
function.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Error from pandas.io.data import DataReader

2014-10-01 Thread ryanshuell
I am trying to run this snippet of code.


from pandas.io.data import DataReader
from pandas import Panel, DataFrame
import datetime

start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2013, 1, 27)

with open('dow.txt') as f:
symbols = f.read().splitlines()  # ['AAPL', 'GLD', 'SPX', 'MCD']

data = dict((symbol, DataReader(symbol, yahoo, start, end, pause=1)) for 
symbol in symbols)
panel = Panel(data).swapaxes('items', 'minor')
closing = panel['Close'].dropna()
closing.head()



I keep getting this error.
Traceback (most recent call last):
  File C:\Python27\download_dow.py, line 1, in module
from pandas.io.data import DataReader
ImportError: No module named pandas.io.data
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-01 Thread Rustom Mody
On Thursday, October 2, 2014 4:07:44 AM UTC+5:30, Shiva wrote:
 Hi,
 I am learning Python (version 3.4) strings.I have a function that takes in a
 parameter and prints it out as given below.

 def donuts(count):
   if count = 5:
 print('Number of donuts: ',count)
   else:
 print('Number of donuts: many')
 return

 It works fine if I call 
 donuts(5)

 It returns:
 we have 5 DN  (as expected)

 However if I do :

 test(donuts(4), 'Number of donuts: 4')

 where test is defined as below:

 def test(got, expected):
   print('got: ', got, 'Expected:' ,expected)
   if got == expected:
 prefix = ' OK '
   else:
 prefix = '  X '
   print (('%s got: %s expected: %s') % (prefix, repr(got), repr(expected)))

 Only 'None' gets passed on to parameter 'got' instead of the expected value
 of 4.
 Any idea why 'None' is getting passed even though calling the donuts(4)
 alone returns the expected value?

Others have given you the correct python-technicalities answer: 

print ≠ return

However given your starting point – I am learning Python – let me try 
a less technical one.

You start from the assumption that your donuts returns 5, which it
seems to in some contexts and not in others.

So by now you know there are 2 kinds of return:

 def foo(x): return x+5
... 
 def bar(x): print(x+5)
... 
 foo(4)
9
 bar(4)
9


So they seem identical here, right?

But as you further discover bar is useless to do anything other than
being called at the command line, whereas foo can be used in all sorts of 
ways: in particular you can use foo to write bar:

def bar(x): print(foo(x))

But not conversely.

So the morals in short: 

1. Stick to the return that works -- python's return statement --
and avoid the return that seems to work -- the print statement
2. print is good for debugging code. When your code is bugfree it should have
few/no prints
3. The official tutorial/docs unfortunately foster bad habits in children by 
showing prints early --
Know better!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-01 Thread Chris Angelico
On Thu, Oct 2, 2014 at 12:29 PM, Rustom Mody rustompm...@gmail.com wrote:
 So by now you know there are 2 kinds of return:

 So the morals in short:

 1. Stick to the return that works -- python's return statement --
 and avoid the return that seems to work -- the print statement

Please. There are not two types of return; there are two completely
different things here. Don't pretend that print is a bad form of
return. It isn't.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Travis Griggs


Sent from my iPhone

 On Oct 1, 2014, at 04:12, Peter Otten __pete...@web.de wrote:
 
 `lambda` is just a fancy way to define a function inline

Not sure fancy is the correct adjective; more like syntactic tartness (a less 
sweet version of syntactic sugar).

:)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Obscuring Python source from end users

2014-10-01 Thread Marko Rauhamaa
Dan Stromberg drsali...@gmail.com:

 On Mon, Sep 29, 2014 at 4:47 AM, Steven D'Aprano
 Yes. Distribute the pyc files only.

 Yes, this is the way it's usually done.

Has the .pyc file format stabilized? A decade ago, my employer shipped
an application as .pyc files but had to ship the matching CPython binary
with it.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue22472] OSErrors should use str and not repr on paths

2014-10-01 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

вівторок, 30-вер-2014 19:26:52 ви написали:
 How do I reconstruct an arbitrary OSError error message using the filename
 parameter?

if not e.args:
msg = ''
elif len(e.args) == 1:
msg = str(e.args[0])
elif len(e.args) = 5:
msg = '[Error %s] %s' % e.args[:2]
if len(e.args)  2:
msg = '%s: %r' % (msg, e.args[2]) # filename
if len(e.args)  4:
msg = '%s - %r' % (msg, e.args[4]) # filename2
else:
msg = str(e.args)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22472
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20079] Add support for glibc supported locales

2014-10-01 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

Thanks, Serhiy.

The patch looks good, except for one nit: the makelocalealias.py normaly also 
generates a list of changes and these are put at the top of the locale_alias 
dictionary.

Could you add that as well ?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20079
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17873] _ctypes/libffi missing bits for aarch64 support

2014-10-01 Thread Andreas Schwab

Andreas Schwab added the comment:

https://build.opensuse.org/package/show/openSUSE:Factory:ARM/python3-base

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17873
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20079] Add support for glibc supported locales

2014-10-01 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The makelocalealias.py generates only a list of removes and updates, not 
additions.

I recommend first apply issue20076, it will eliminate most additions.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20079
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19113] duplicate test names in Lib/ctypes/test/test_functions.py

2014-10-01 Thread Xavier de Gaye

Xavier de Gaye added the comment:

This issue has been entered while checking for duplicate test names in issue 
16079.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19113
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21963] 2.7.8 backport of Issue1856 (avoid daemon thread problems at shutdown) breaks ceph

2014-10-01 Thread STINNER Victor

STINNER Victor added the comment:

Oh by the way, I also prefer to revert the commit.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21963
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21574] Port image types detections from PIL to the imghdr module

2014-10-01 Thread Andriy Sokolovskiy

Andriy Sokolovskiy added the comment:

I'll try to do this issue.
https://mail.python.org/mailman/private/core-mentorship/2014-October/002766.html

--
nosy: +coldmind

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21574
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22492] small addition to print() docs: no binary streams.

2014-10-01 Thread Georg Brandl

Georg Brandl added the comment:

Looks good.

 sys.stdout, when rebound to a binary mode file

Not sure that is supported in any way :)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22492
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22531] Turn contextlib.{redirect_stdout, suppress} into ContextDecorators

2014-10-01 Thread Antony Lee

New submission from Antony Lee:

A small lib improvement suggestion could be to make contextlib.redirect_stdout 
and contextlib.suppress inherit from ContextDecorator.

As a side note, the source of contextlib has some classes inheriting explicitly 
from object while others don't, so perhaps this can be harmonized at the same 
time.

--
components: Library (Lib)
messages: 228065
nosy: Antony.Lee
priority: normal
severity: normal
status: open
title: Turn contextlib.{redirect_stdout,suppress} into ContextDecorators
versions: Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22531
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20076] Add UTF-8 locale aliases

2014-10-01 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

Thanks, Serhiy

The patch looks good. Please apply.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20076
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20079] Add support for glibc supported locales

2014-10-01 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

On 01.10.2014 09:52, Serhiy Storchaka wrote:
 
 The makelocalealias.py generates only a list of removes and updates, not 
 additions.

Ah, ok.

 I recommend first apply issue20076, it will eliminate most additions.

Agreed. Please apply both patches.

Thanks,
-- 
Marc-Andre Lemburg
eGenix.com

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20079
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22494] default logging time string is not localized

2014-10-01 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I'm a bit surprised here, since the comma is not the default (US) decimal point.

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22494
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21971] Index and update turtledemo doc.

2014-10-01 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
keywords: +easy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21971
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22001] containers same does not always mean __eq__.

2014-10-01 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22001
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21999] shlex: bug in posix mode handling of empty strings

2014-10-01 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21999
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22494] default logging time string is not localized

2014-10-01 Thread Georg Brandl

Georg Brandl added the comment:

It's not so surprising, since the string before the milliseconds part is a 
strftime() result, not a whole number.  The decimal point need not necessarily 
be used for this.

Just like the rest of the default time format, it is probably best for the 
millisecond part to be locale independent unless chosen to be locale aware by 
the programmer.

Using the comma is apparently common among loggers. I've seen it in logs 
generated by log4j and log4cpp as well.

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22494
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22531] Turn contextlib.{redirect_stdout, suppress} into ContextDecorators

2014-10-01 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
nosy: +ncoghlan

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22531
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22494] default logging time string is not localized

2014-10-01 Thread Vinay Sajip

Vinay Sajip added the comment:

ISO 8601 governs the format used. From the Wikipedia article on the same:

A decimal mark, either a comma or a dot (without any preference as stated in 
resolution 10 of the 22nd General Conference CGPM in 2003, but with a 
preference for a comma according to ISO 8601:2004) is used as a separator 
between the time element and its fraction.

--
resolution:  - not a bug
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22494
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Eric V. Smith

Eric V. Smith added the comment:

Is there some particular problem you're trying to solve, which this would make 
easier?

Without a use case, I'm -1.

--
nosy: +eric.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Ram Rachum

Ram Rachum added the comment:

I needed it for an internal calculation in a combinatorics package I'm writing. 
Do you want me to take the time to explain the calculation? It's quite complex.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22532] A suggested change

2014-10-01 Thread Padmanabhan Tr

New submission from Padmanabhan Tr:

Take a complex number n = 3+4j. n.real is taken as 3.0  n.imag as 4.0 in 
Python3.  One has to use the int(0 function to get back the parts as integers.  
I guess this is a compiler error?

--
messages: 228073
nosy: Padmanabhan.Tr
priority: normal
severity: normal
status: open
title: A suggested change
type: compile error
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22532
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22472] OSErrors should use str and not repr on paths

2014-10-01 Thread R. David Murray

R. David Murray added the comment:

Thank you, Serhiy.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22472
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22531] Turn contextlib.{redirect_stdout, suppress} into ContextDecorators

2014-10-01 Thread R. David Murray

R. David Murray added the comment:

-100 on doing this for suppress.  That would be exactly the kind of 
wrong-headed code that I was worried that context manager would invite.

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22531
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22532] A suggested change

2014-10-01 Thread Geoffrey Spear

Geoffrey Spear added the comment:

From the documentation: Complex numbers have a real and imaginary part, which 
are each a floating point number.

Needing to use int() to convert these floats to integers is not a bug, it's the 
expected behavior.

--
nosy: +geoffreyspear

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22532
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22532] A suggested change

2014-10-01 Thread Geoffrey Spear

Changes by Geoffrey Spear geoffsp...@gmail.com:


--
components: +Interpreter Core
type: compile error - behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22532
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22532] A suggested change

2014-10-01 Thread Eric V. Smith

Changes by Eric V. Smith e...@trueblade.com:


--
resolution:  - not a bug
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22532
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Eric V. Smith

Eric V. Smith added the comment:

No need to explain it. It sounds like it's not generally useful, so I'm still 
-1.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22531] Turn contextlib.{redirect_stdout, suppress} into ContextDecorators

2014-10-01 Thread Nick Coghlan

Nick Coghlan added the comment:

Aye, suppress is only intended for use around a single line of code. Using it 
for an entire function would be OnError Resume Next levels of poor coding 
style.

I'm also -1 on implicitly wrapping redirect_stdout around functions due to the 
immediate thread safety problem doing so introduces. The stdout redirection 
really only makes sense in a single-threaded scripting context, and using it as 
a decorator rather than inline makes it far too easy to inadvertently violate 
that constraint.

As far as the explicitly inherit from object or not goes, it wouldn't 
surprise me if that's just a migrated from Python 2 vs first introduced in 
Python 3 distinction. It's not something I would change solely for the sake of 
consistency.

--
resolution:  - rejected
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22531
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22528] Missing hint to source code

2014-10-01 Thread Friedrich Spee von Langenfeld

Friedrich Spee von Langenfeld added the comment:

Excuse me, but it would be nice to fix the documentation of the modules 
symtable and compileall too. Thanks.

--
resolution: fixed - 
status: closed - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22528
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22532] A suggested change

2014-10-01 Thread Padmanabhan Tr

Padmanabhan Tr added the comment:

Dear Mr SpearThanks for the prompt response  clarification.(in Python) If the 
real  imaginary parts of numbers you deal with are integers, results of 
operations (except division)  - like +, -, *, **, - appear with respective 
integers as real  imginary parts.  In line with these, changes in '.real'  
'.imag' may be desirable?

 On Wednesday, October 1, 2014 8:19 PM, Eric V. Smith 
rep...@bugs.python.org wrote:

Changes by Eric V. Smith e...@trueblade.com:

--
resolution:  - not a bug
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22532
___

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22532
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Even if you don't find it useful, Eric, it doesn't take up the method space. 
You can very easily ignore it, there's no cognitive burden.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Ethan Furman

Ethan Furman added the comment:

Curiousity question:  What happens if you try to sort a list of partially 
ordered Counters?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 If it is so specialized as to only be needed in complex combinatorial 
 calculations

How do you know it is only needed in complex combinatorial calculations?

 What happens if you try to sort a list of partially ordered Counters?

Try it with partially ordered sets.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Ethan Furman

Ethan Furman added the comment:

If it is so specialized as to only be needed in complex combinatorial 
calculations, does it belong in the general-purpose part of the language?  
After all, we have the math and cmath modules for more specialized arithmetic 
operations.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Ram Rachum

Ram Rachum added the comment:

I don't see why it's so hard to imagine how this will be used. Say I have a 
counter signifying how many of each product I have in my warehouse, and I have 
another counter saying how many of each product a client wants. I may use 
`counter2 = counter1` to check whether there are enough products in stock. 
Sounds straightforward to me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Ethan Furman

Ethan Furman added the comment:

-- s1 = set([1])
-- s2 = set([1, 2])
-- s3 = set([1, 2, 3])
-- s4 = set([2])
-- s5 = set([2, 3])
-- s6 = set([3])

-- l = [s1, s2, s3, s4, s5, s6]
-- sorted(l)
[{1}, {2}, {1, 2}, {3}, {2, 3}, {1, 2, 3}]

-- s1  s4
False

-- s4  s2
True

-- s1  s2
True

-- s4  s6
False

-- l = [s1, s4]
-- sorted(l)
[{1}, {2}]

-- sorted(l)
[{1}, {2}]


Looks horribly messy to me.  In the last example we can see that neither s1 nor 
s4 are smaller, yet s1 is consistently put first.

On the other hand, I suppose it's okay for Counter to have this behavior since 
it's already in sets.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Steven D'Aprano

Steven D'Aprano added the comment:

Ethan said:

 If it is so specialized as to only be needed in complex combinatorial 
 calculations, does it belong in the general-purpose part of the 
 language?

It's a multi-set, a general purpose and fairly fundamental data type.

https://en.wikipedia.org/wiki/Set_%28abstract_data_type%29#Multiset

And later:

 Curiousity question:  What happens if you try to sort a list of 
 partially ordered Counters?

The same thing that happens when you sort a list of any partially 
ordered objects, such as sets:

py sorted([{1, 2, 3, 4}, {2, 4}, {1, 3}, {2, 3, 4}, {1, 2, 3}])
[{2, 4}, {1, 3}, {2, 3, 4}, {1, 2, 3}, {1, 2, 3, 4}]

You get some order, but since sorting assumes a total order, not just 
partial order, the result isn't really meaningful, and will very likely 
depend on the initial order of the items. If that worries you, then 
don't sort items that implement only a partial order.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9949] os.path.realpath on Windows does not follow symbolic links

2014-10-01 Thread Thomas Kluyver

Changes by Thomas Kluyver tak...@gmail.com:


--
nosy: +takluyver

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9949
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Ethan Furman

Ethan Furman added the comment:

I'll go with +0.5.  :)

If this goes in, I think a missing key in either Counter should default to 0 
for purposes of the ordering.

--
stage:  - test needed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Ram Rachum

Ram Rachum added the comment:

If/when there's general agreement that this functionality should be merged in 
(assuming the implementation is acceptable), let me know and I'll be happy to 
write the code and tests.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20218] Add methods to `pathlib.Path`: `write_text`, `read_text`, `write_bytes`, `read_bytes`

2014-10-01 Thread Roundup Robot

Roundup Robot added the comment:

New changeset a4da150fbfd4 by Georg Brandl in branch 'default':
Closes #20218: Added convenience methods read_text/write_text and read_bytes/
https://hg.python.org/cpython/rev/a4da150fbfd4

--
nosy: +python-dev
resolution:  - fixed
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20218
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20218] Add methods to `pathlib.Path`: `write_text`, `read_text`, `write_bytes`, `read_bytes`

2014-10-01 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Thanks, Georg!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20218
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22515] Implement partial order on Counter

2014-10-01 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 I'll go with +0.5.  :)

I was going to make a joke about Counters only accepting integral values, but 
the constructor is actually quite laxist:

 Counter({'a': 2.5})
Counter({'a': 2.5})
 Counter({'a': 2.5 + 1j})
Counter({'a': (2.5+1j)})
 Counter({'a': 'b'})
Counter({'a': 'b'})

(!)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22515
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19529] Fix unicode_aswidechar() with 4byte unicode and 2byte wchar_t, for AIX

2014-10-01 Thread Georg Brandl

Georg Brandl added the comment:

Committed in 18983332626b.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19529
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >