[docs] global

Scot Kelly skelly at passportcapital.com
Wed Dec 1 19:08:05 CET 2010

Re: http://docs.python.org/tutorial/controlflow.html

And http://docs.python.org/reference/simple_stmts.html#global


1. The documentation for the global statement would be improved if it
also had the paragraph from the tutorial.


2. The tutorial paragraph does not address that all references to the
variable name become local if an assignment occurs in a function.


SomeVar  = 12

def MyFunc()

  Print 'SomeVar', SomeVar

  SomeVar = 123

  Print 'SomeVar', SomeVar


An UnboundLocalError occurs on the first line, but not if we comment out
the assignment. 


3. Also, assignments to global variables ARE allowed (without providing
a global statement) if the assignment cannot be interpreted as creating
a symbol...

#This code works

SomeVar  = [12, 34]

def MyFunc()

  Print 'SomeVar', SomeVar[0]

  SomeVar[0] = 123

  Print 'SomeVar', SomeVar[0]



30 Hotaling Place, Suite 300
San Francisco, CA 94111

Scot Kelly
Tel 415-525-8910
Fax 415-321-4620
skelly at passportcapital.com

CONFIDENTIALITY: The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this message in error, please contact the sender and delete the material from all computers.

E-mail transmissions cannot be guaranteed to be secure or error-free. The sender does not accept liability for any errors or omissions in the contents of this message which arise as a result of this e-mail transmission. If verification is required, then please request a hard-copy version.

We screen for viruses on a routine basis. The recipient should check this e-mail and any attachments for viruses. We make no representation or warranty as to the absence of viruses in this e-mail or any attachments. Please note that to ensure regulatory compliance and for the protection of our investors and business, we may monitor and read e-mails sent to and from our servers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20101201/c62059ed/attachment.html>

More information about the docs mailing list