Beginner needs advice

Chris Angelico rosuav at gmail.com
Sat May 28 22:26:34 EDT 2011


On Sun, May 29, 2011 at 12:02 PM, harrismh777 <harrismh777 at charter.net> wrote:
> Chris Angelico wrote:
>> Both versions of Python are
>> the same language, because they "think" the same way;
>     I see your point. But, knowing that 3.x "thinks" like 2.x is not helpful
> when we all know that languages don't think, people do.

I was being (deliberately) sloppy with the English language there, but
I was referring to the fundamental philosophies of Python, which are
common across both versions (and, presumably, most/all of them can be
seen in Python 1 too; I've never used Python 1).

>> Little syntactic
>> differences like whether 'print' is a function or a statement, and
>> whether the simple slash operator between two ints returns a float,
>> and the fact that Unicode is the default string type, are
>> comparatively minor; on 'most every philosophical point, the two
>> dialects agree.
>
>   Minor, yes, .... until you need to make something work--- only to be
> frustrated to find that a detail that was not expected has risen to bite a
> sensitive place...   :)

I get far worse than those when I switch between languages and forget
operator precedence, or forget that function X has its parameters the
other way around, or whatever. They are minor, and if you're not 100%
familiar with the language you're writing in, you should probably have
its docs handy anyway.

The print function will bite you instantly, you'll know what's wrong
as soon as you try to run it. Unicode strings, too, will usually throw
a nice tidy exception. The only one that's going to really sting you
is division, and it's so easy to deal with that one as you code
(always use // for flooring).

> instance, how do we reload a module in 2.x...  with, um, reload.   This has
> always been the way... every book says so, and every one of us has
> re-invoked a .py file by using relaod.  Reload doesn't even work on 3.x
> without an import.

>From what I gather, Python simply isn't designed with that sort of
"live reload" in mind. Just terminate it and start over, it's easier.
If you want a system where you reload parts of it without bringing
things down, either build it manually (loading another piece of code,
and maybe reassigning some state variables that have your functions),
or pick a different language - Pike does this excellently. That's not
an indictment of Python; it's simply that Python is not everything.

> Some of the posts here are referring to the two languages as partially
> incompatible....   reminds me of that line from Princess Bride... "... he's
> not dead, hes only mostly dead!... and mostly dead is partly alive!"  To say
> that 3.x is partly compatible with 2.x is silly, but to say that 3.x
> 'thinks' the same way as 2.x is almost pythonesque...  I almost like that...

Mostly compatible is still partly incompatible? Sure. But "mostly
compatible" is Python 2.6.6 and Python 2.7.1, too. It's easy to write
one codebase that runs under multiple Python versions; certainly it's
a lot easier than writing one source file that's both Python and C,
for instance. And the same lines of code will be doing the same work
(unlike most polyglottisms, where one language's code is another
language's comments). There is a subset of Python 2 that is also a
subset of Python 3, and this intersection is quite large.

Chris Angelico



More information about the Python-list mailing list