× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



First of all I did follow your advice and am working through the tutorial.

But I happened to have a short-term need for a simple text to pdf convertor and googled for that - that resulted in me finding http://code.activestate.com/recipes/532908-text-to-pdf-converter-rewrite/ which in this and its original version had received many “thank you’d” and other references. It was a short enough piece of code and with the “thanks” I figured it was probably a reasonably good example - bad assumption apparently.

Thanks for your advice.


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Jul 15, 2015, at 1:22 PM, John Yeung <gallium.arsenide@xxxxxxxxx> wrote:

On Wed, Jul 15, 2015 at 11:14 AM, Jon Paris <jon.paris@xxxxxxxxxxxxxx> wrote:
Thanks for the offer. Similar changes have occurred in PHP but the transition was more gradual with a lot of backward compatibility - or so it seems to me. In 5+ years I think I have only encountered about 5 things that required real thought to refactor.

The transition from Python 2 to 3 is arguably bigger than any of the
PHP "major version" changes that have come to fruition. Python 3 is
roughly what PHP 6 was supposed to be. Both had as their centerpiece
the conversion of their string underpinnings to Unicode. Unlike PHP 6,
Python 3 actually happened.

No breaking changes for Python have ever been done before (so if you
wrote something for Python 1.5.2, it should still work as-is in Python
2.7.9), and as you might expect, no further breaking changes are
planned for the future. ;)

Here’s one example of a 2to3 issue. Original lines are prefixed - converted are + (I know you know that but others will be reading!)

- except IOError, (strerror, errno):
- print 'Error: Could not open file to read --->', self._ifile
+ except IOError as xxx_todo_changeme:
+ (strerror, errno) = xxx_todo_changeme.args
+ print('Error: Could not open file to read --->', self._ifile)
sys.exit(3)

It is the “xxx_todo_changeme” bits that confuse. Am I supposed to just give it a name of my choosing ? or ?

You really just dove in, didn't you? You didn't like my recommendation
of starting with the basics and moving up? (Specifically, working
through the official tutorial.)

I have to ask again: Where are you seeing this?

The Python 2 code you're starting with there isn't very good. What
it's trying to say is that IOError is supposed to come in two pieces,
and they want the first piece to be assigned to the variable
`strerror` and the second piece to `errno`. Now, that's a very
old-school exception syntax, even for Python 2. On top of that, the
first piece of the IOError is a number and the second piece is a
string. So just bad all around.

The short answer is: yes, just change `xxx_todo_changeme` to whatever
you like. But (1) if you want to keep the error number and the error
message string around, you'll want to reverse `strerror` and `errno`
for sanity; and (2) I don't see either of those actually being used,
so you could just as well get rid of them entirely. (Of course I can't
see past the snippet you've quoted, but it strikes me as unlikely that
those two variables matter, since the very next thing that happens is
exiting. Plus, if they did matter, one would expect that having
`strerror` and `errno` mixed up would have manifested in a noticeable
way at some point.)

So the "more correct" answer is: the Python 2 code probably should
have looked like this in the first place:

except IOError:
print 'Error: Could not open file to read --->', self._ifile

and then the Python 3 code would simply add the parens for print:

except IOError:
print('Error: Could not open file to read --->', self._ifile)

which 2to3 could have fixed on its own.

It's really frustrating to see beginners struggling with code that is
written by folks who are most likely not experts in the language being
learned. (The code Buck shared was also not written by a Python
expert. It was serviceable, but definitely not idiomatic.)

There were even just blatant errors in an IT Jungle article meant to
be an introduction to iSeriesPython (which was at 2.5 at the time).
With the blind leading the blind, someone is bound to get hurt. :(

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.