Re: variable declaration

From: Brian van den Broek (bvande_at_po-box.mcgill.ca)
Date: 02/08/05


Date: Tue, 08 Feb 2005 11:55:07 -0500
To: python-list@python.org

Brian van den Broek said unto the world upon 2005-02-07 20:36:
> Steve Holden said unto the world upon 2005-02-07 17:51:

<SNIP>

>> The reason global is a wart can clearly be seen in the following example:
>>
>> >>> x = 3
>> >>> def f(tf, v):
>> ... if tf:
>> ... global x
>> ... x = v
>> ...
>> >>> f(0, 5)
>> >>> x
>> 5
>> >>>

<SNIP>

> Hi,
>
> Steve's example makes my brain hurt. :-)
>
> I'd appreciate it if someone could tell me if I am understanding the
> example correctly. (My grasp of the terminology and issues at play is a
> bit shaky.)

<SNIP>

> Thanks for any confirmation of my understanding / rectification of same.
> Best,
>
> Brian vdB

Thanks to everyone whose contributed to this sub-thread! I've learned
a lot. :-)

And, for posterity, some one wrote me off-list to correct my claim
that in

if False:
     # thousands of lines of code here

the thousands of lines "would never get executed". Simplifying their
example, they pointed out:

>>> False = 'evil trickery'
>>> if False:
... print 'Surprise!'
...
Surprise!
>>>

Which leads me naturally to the differences between 'if False:' and
'if ):' that Duncan Booth pointed to. (Where'd I put the Tylenol.)

Thanks again to all,

Brian vdB



Relevant Pages

  • Re: The Origins of Zürich...
    ... And the sound you are hearing, ladies and gents, is the sound of Brian ... have noticed I ignore the attacks, I snip them, and focus on the "meat" of ... gristle along with the tid bits of tasty meat, ...
    (sci.lang)
  • Re: Argogroup being wound up
    ... The first of the ordinary shares were issued to punters at 50p ... income tax and with freedom from capital gains tax. ... Brian Carroll, Ripon, N Yorks, UK briancarroll at f2s dot com ...
    (comp.sys.acorn.misc)
  • Re: Requalivahanus
    ... > appears in Latinized form in the dative: ... > reads <Deo Requalivahano Q. Aprianus Fructus ex imperio pro ... Ah, thank you, Brian! ...
    (sci.lang)
  • Re: Delphi 2005 Update 4
    ... "Brian Moelk"wrote ... > The palpable tension that exists now is when the division between their ... > perceptions become so great they cannot see the common ground between them. ...
    (borland.public.delphi.non-technical)
  • [OT] Re: Python becoming less Lisp-like
    ... news.sydney.pipenetworks.com said unto the world upon 2005-03-16 05:57: ... <SNIP> ... Anyone else having images of mimes engaged in street fights? ... Brian vdB ...
    (comp.lang.python)