Re: A first draft python fact sheet, extracted from the Python Ref Manual

Tim Peters (
Wed, 22 Jun 94 00:57:52 -0400

> [ken]
> ... what's the deal with the overlap in the ref manual and the lib ref
> manual? It seems like the lib ref manual provides more up-to-date and
> exact details on the things it does cover ...

Keeping docs up to date is a soul-numbing activity, & I suspect the lib
ref is usually closest to the truth just because the lib ref has the
highest rate of change (meaning that Guido simply spends more time
editing that doc than any of the others).

> > > operators: 'not', 'and', 'or'; binary ones shortstop
> > [tim] ?????????????????????

> I was referring to the fact that successive conditions are evaluated
> depending on the values of preceeding ones - is that short-circuiting?

Ah! I misread it -- could only picture a string of binary 1 bits
and couldn't figure out _what_ that had to do with Python Baseball <grin>.

Suggest that

operators: not x -> if x then 0 else 1
x and y -> if x then y else x
x or y -> if x then x else y

would bring out all the subtleties in a clearer way; e.g., it's sometimes
important to know that "[] and [3]" returns "[]", while "[] or 'python'"
returns "'python'". I.e., the truth is subtler than _just_ "short-

> > ...
> > Today, every piece of code executes in some module, and the global ns
> > for the code is simply the module's namespace; the "global ns of
> > cb/caller" clauses always trace a chain back up to "Module", "Script"
> > or "Interactive cmd". The only exception is when the global ns is
> > explicitly overridden via argument to exec/eval/execfile.

> That makes sense - do you think it ought to be explicitly articulated in
> the cheat sheet? Do you have suggestions how i might fit it in?

How about:

Name space search order: local, global, builtin

Code Block scopes (ns = name space, cb = containing block)
gns = global ns = containing module's ns, unless args override

Code block type Local ns Notes
--------------- -------- -----
Module same as gns
Script same as gns gns is __main__
Interactive cmd same as gns gns=is __main__
Class def new ns
Function body new ns
'exec' string local ns of cb (or args)
'eval' string local ns of caller (or args)
'execfile' file local ns of caller (or args)
'input' expr local ns of caller

> > Nit: (-sys.maxint-1)/-1 doesn't raise OverflowError, but should.

> I may want to put this in my 'useful hints and idioms' section.

That the range of ints is -sys.maxint-1 thur sys.maxint inclusive is a
useful hint, but the failure to raise OverflowError on that division
example is a bug <wink>.

> [another stab at summarizing dict keys]


telegraphically y'rs - tim

Tim Peters
not speaking for Kendall Square Research Corp