[Tutor] when is a generator "smart?"

Jim Mooney cybervigilante at gmail.com
Mon Jun 3 04:50:48 CEST 2013


On 2 June 2013 17:23, Marc Tompkins <marc.tompkins at gmail.com> wrote:
>
> I saw a quote a long time ago; I'd love to attribute it properly, but...:
> "God created the world in just seven days.  But then, He had no installed
> base."

Using Python 2.7 on Windows 7

In regard to that, I just tried importing Tkinter, according to a
guide I'm using. Except the guide is using tkinter and not Tkinter,
but Py27 has Tkinter. Lord knows why they bothered to change one lousy
letter - it would be less confusing to have given it an entirely new
name like notyourmothersKinter ;') Also, lib-tk didn't have __init__
for some reason so when I changed to Big T for Py27 it still didn't
import. I put __init__ in, and still no luck, so I put lib-tk into
PYTHONPATH and it worked, but then I got ambitious with PYTHONPATH and
caused a bigger problem (below).

So far, except for changing tkinter back to Tkinter, all the basic
programs I've tried so far work the same, so I'm mystified why they
bothered to change only that one letter. At least raw_input and input
are obvious changes. I think hit-you-in-the-face changes are better
than creeping changes.

Even though it was in between major versions, which I didn't like, I
decided on Python instead of Ruby since Python does a lot more stuff,
and I love enforced parentheses (no style-wars, dizzying nested
braces, or tiresome deciding what style to use, which I recall from
webmastering.)

But at times it gets confusing. I searched the web for differences
between 2.7 and 3.3, but instead of a simple listing for beginners,
every reference I found went into depth so complex I don't fathom it
at this point. Rather like much of the docs, which seem to assume you
already know what you're doing, which I don't. What I'm looking for is
something basic like this simple memory-jogging list I'm slowly
building in Clipmate as I get unconfused ;')

Py 2.7, Py 3.3
raw_input, input
print, print()
int a / int b = integer division, int a / int b = normal division and
// is int division
'my %s ate my %' % ('dog','shoes'), 'my {0} ate my
{1}'.format('dog','shoes') --backported
range makes a list, range makes an iterator (xrange for an iterator in 2.7)
sort() sorts in place, sorted() returns a list - actually, I think
that's in both recent Pys.
Tkinter is now tkinter - Lord knows why they bothered doing that

On top of that Py 3.3 just died on me by trying to run 2.7s codec, so
I realized PYTHONPATH was just causing trouble and got rid of it:

C:\Python33>python
Fatal Python error: Py_Initializ
  File "C:\Python27\Lib\encoding
    raise CodecRegistryError,\

But it's always fun to see a Fatal Error.

It's no doubt conflicting with Windows and its awful registry, so now
tkinter/Tkinter works on both Pys and the problems are solved - after
a few hours.

However, I did find I was wrong to blame PyScripter. Since I don't
have Wing Pro, which will do multiple Pys easily, I set up Wing 101
for Py 2.7 and PyScripter for Py 3.3. When PyScripter failed twice I
blamed it, but I now realize each time was when I went fiddling with
PYTHONPATH, which works much more nicely on Windows now that it's not
there at all ;')

This may all seem overly complex for beginning, but I'm patient and I
figure I'll have to learn the differences sooner or later, since 2.7
is lingering. Besides that, I liked the Lutz books and got both the
beginner Learning "Python," to be followed by the climb-the-mountain
"Programming Python." Only Programming Python has all examples in 3
and scants 2, while the only "Learning Python" book available is
mostly for 2 (I think the new edition of "Learning" comes out this
month, but I'm all spent out on books for now.) So I'll be going back
and forth at some point anyway.

Someday I may get back to learning Python. Still, it's all in good
fun. Tracking this stuff down is better than reading a detective novel
;')

Jim


More information about the Tutor mailing list