Re: Neat little programming puzzle

2014-12-15 Thread Ian Kelly
On Mon, Dec 15, 2014 at 10:46 PM, Jason Swails wrote: > > This was a problem posed to me, which I solved in Python. I thought it was neat and enjoyed the exercise of working through it; feel free to ignore. For people looking for little projects to practice their skills with (or a simple distrac

Neat little programming puzzle

2014-12-15 Thread Jason Swails
This was a problem posed to me, which I solved in Python. I thought it was neat and enjoyed the exercise of working through it; feel free to ignore. For people looking for little projects to practice their skills with (or a simple distraction), read on. You have a triangle of numbers such that ea

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Ben Finney
Steven D'Aprano writes: > If you don't have and won't open an account on the tracker, if you can > come up with a minimal example that demonstrates the issue, I'll open > an issue for you. (But I'd rather you did it yourself :-) Thank you for the offer. Fortunately, the Python bug tracker does n

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Ben Finney
Ethan Furman writes: > On 12/15/2014 05:36 PM, Ben Finney wrote: > > I'm increasingly of the opinion this is a subtle bug in ‘__import__’ > > that should be fixed instead of worked around. And other people agree: https://bugs.python.org/issue21720>. > Of course. But you'll still need to work ar

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Steven D'Aprano
Ben Finney wrote: > I'm increasingly of the opinion this is a subtle bug in ‘__import__’ > that should be fixed instead of worked around. But it will likely be > rejected because the documentation advises against using ‘__import__’. > Bah. I think its worth raising an issue on the bug tracker and

Re: Portable code: ‘from __future__ import unicode_literals’ a good idea?

2014-12-15 Thread Ben Finney
Ned Batchelder writes: > On 12/15/14 7:42 PM, Ben Finney wrote: > > As for the advice to avoid such a declaration, you're arguing against > > the official guide for porting Python 2 code to 2-and-3 compatible code: > > > > For text you should either use the from __future__ import > > un

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Ethan Furman
On 12/15/2014 05:36 PM, Ben Finney wrote: > > That's not the issue at all. I know how to declare a literal such that > it is Unicode in Python 2 and Python 3 (that's what the ‘from __future__ > import unicode_literals’ does). > > Rather, the problem is ‘__import__’ having incompatible expectation

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Ben Finney
Ethan Furman writes: > On 12/14/2014 11:29 PM, Ben Finney wrote: > > The ‘__import__’ built-in function, though, is tripping up. > > One work-around I have used is: > > if isinstance(some_var, bytes): > some_var = some_var.decode('ascii') > # at this point some_var is unicode in both Py

Re: Portable code: ‘from __future__ import unicode_literals’ a good idea?

2014-12-15 Thread Ned Batchelder
On 12/15/14 7:42 PM, Ben Finney wrote: As for the advice to avoid such a declaration, you're arguing against the official guide for porting Python 2 code to 2-and-3 compatible code: For text you should either use the from __future__ import unicode_literals statement or add a u prefix t

Re: Portable code: ‘from __future__ import unicode_literals’ a good idea? (was: Portable code: __import__ demands different string types between 2 and 3)

2014-12-15 Thread Devin Jeanpierre
On Mon, Dec 15, 2014 at 4:42 PM, Ben Finney wrote: > Devin Jeanpierre writes: > >> On Sun, Dec 14, 2014 at 11:29 PM, Ben Finney >> wrote: >> > from __future__ import unicode_literals >> >> Ordinarily, for 2.x/3.3+ code I would suggest not doing this -- >> instead, b'...' for bytes, u'...' f

Portable code: ‘from __future__ import unicode_literals’ a good idea? (was: Portable code: __import__ demands different string types between 2 and 3)

2014-12-15 Thread Ben Finney
Devin Jeanpierre writes: > On Sun, Dec 14, 2014 at 11:29 PM, Ben Finney > wrote: > > from __future__ import unicode_literals > > Ordinarily, for 2.x/3.3+ code I would suggest not doing this -- > instead, b'...' for bytes, u'...' for unicode, and '...' for native > "string" type (bytes on 2.

[ANN] pyspread 0.4

2014-12-15 Thread Martin Manns
pyspread 0.4 Pyspread 0.4 is released. In this release, rendering has switched to Cairo, which enhances quality and performance. Grid content can now be exported into high quality PDF and SVG files. Cells can now display SVG images and text with markups. The nn function

RE: Classes - converting external function to class's method.

2014-12-15 Thread Ivan Evstegneev
Again Thanks for your help. I saw that there was a debate about "namespace" nature. That is what a book says about it(Learning Python 5 Ed. By Mark Lutz): * "Classes and Instances Although they are technically two separate object types in the Python

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Ethan Furman
On 12/14/2014 11:29 PM, Ben Finney wrote: > > This entails, I believe, the admonition to ensure text literals are > Unicode by default:: > > from __future__ import unicode_literals > > and to specify bytes literals explicitly with ‘b'wibble'’ if needed. For some scripts this works great (I

Python {executable templates from XSLT, code generation tool}

2014-12-15 Thread Jean-Baptiste Braun
Hi, I'm searching a tool to translate an xsl file to executable python code. I know how to execute xslt with python. What I want is to process my xslt rules *in* python. Example : Mr Mrs I would like it to be translated in a python test statement. Does anyone know something like this ? Or

ANN: Benchmarker 4.0.0 released - small but awesome benchmark utility

2014-12-15 Thread Makoto Kuwata
I released Benchmarker ver 4.0.0 http://pypi.python.org/pypi/Benchmarker/ http://pythonhosted.org/Benchmarker/ Benchmarker is a small utility to benchmark your code. *NOTICE* This release doesn't have compatibility with ver 3.x. Installation $ sudo pip install Benchmarker Ex

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Steven D'Aprano
Ben Finney wrote: > Howdy all, > > What should I do, in a world where all text literals are Unicode by > default, to make ‘__import__’ work in both Python 2 and 3? One approach I frequently use is a conditional import. Off the top of my head, I'd do something like this: try: import builtin

Re: "**" in python

2014-12-15 Thread Steven D'Aprano
Albert van der Horst wrote: > With some perseverance, you can ask the interpreter what `` ** '' > does: > > help(**) > > maybe so? > help('**') > Indeed, a whole description. Yes! Well spotted! -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: encoding name mappings in codecs.py with email/charset.py

2014-12-15 Thread Stefanos Karasavvidis
I played around with changing the names in the aliases.py and locale.py files (from iso8859 to iso-88559), but this broke mailman. I ended up changing the charset.py file input_charset = codecs.lookup(input_charset).name except LookupError: pass if (inpu

Re: "**" in python

2014-12-15 Thread Albert van der Horst
In article , Skip Montanaro wrote: >-=-=-=-=-=- > >I want to add one more thing to the other responses. People new to Python >often seem unaware that being an interpreted language, often the best way >to figure something out is to simply try it at the interpreter prompt. The >OP saw "var ** 2" in

Re: is_ as method or property?

2014-12-15 Thread Mateusz Loskot
On 13 December 2014 at 12:24, Steven D'Aprano wrote: > Mateusz Loskot wrote: > >> On 12 December 2014 at 12:26, Chris Angelico wrote: >>> On Fri, Dec 12, 2014 at 10:21 PM, Mateusz Loskot >>> wrote: I've got several cases which are not obvious to me. For instance, class Foo has a boolea

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Devin Jeanpierre
On Sun, Dec 14, 2014 at 11:29 PM, Ben Finney wrote: > I'm slowly learning about making Python code that will run under both > Python 2 (version 2.6 or above) and Python 3 (version 3.2 or above). > > This entails, I believe, the admonition to ensure text literals are > Unicode by default:: > >