[Tutor] Question about why a list variable is apparently global.

boB Stepp robertvstepp at gmail.com
Thu Nov 27 16:00:48 CET 2014


On Thu, Nov 27, 2014 at 4:51 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> On 27/11/14 04:18, boB Stepp wrote:

[...]

>> So any variables lower in the program are accessible to those above it?
>
>
> No.
> Its not whether they are defined above or below each other its the level of
> indentation. Both f and g are defined at the outer level of the module. They
> are therefore global(within that module) and can each see the other. Steven
> could just as well have written:
>
> def f(): return "Hello!"
>
> def g(): return f()

Level of indentation is the key? Can you give me an example, not
involving functions, where a variable is defined at an "inner" level
of indentation, but is not accessible at the outermost level of
indentation? I tried to construct such an example myself, but was
unsuccessful.

[...]

>> day today. Despite having Grayson's book on Tkinter, it has been hard
>> going for me.
>
>
> Grayson's book is hard going and is very old now so some things have
> improved and changed. In particular you now have access to Tix and ttf
> on newer versions of Python. But since you are still using 2.4 that probably
> doesn't affect you! :-)

That is the main reason I got the book, because of the version of
Python I am forced to use at work.

> However, if you have access to it, you should consider getting Mark Lutz's
> book Programming Python (4th ed). It's a massive 1600 pages
> of which 400+ are about Tkinter programming (more than Grayson!)

I actually purchased that book and his 4th edition of Learning Python
when I first started getting interested in Python a couple of years
ago. I will check out his Tkinter coverage and see if it is easier
going.

> And there is the bonus of 1200 other pages of detailed info about
> the OS, Networking, databases etc. Again its a bit dry but full
> of information.

I looked at his discussion of scope last night in the latter book. I
still don't think I am fully getting it yet. But I will continue to
persevere.

-- 
boB


More information about the Tutor mailing list