Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enclosing Scope missing from namespace in Tutorial #40644

Closed
brianvanden mannequin opened this issue Jul 26, 2004 · 3 comments
Closed

Enclosing Scope missing from namespace in Tutorial #40644

brianvanden mannequin opened this issue Jul 26, 2004 · 3 comments
Assignees
Labels
docs Documentation in the Doc dir easy

Comments

@brianvanden
Copy link
Mannequin

brianvanden mannequin commented Jul 26, 2004

BPO 997912
Nosy @birkenfeld

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2008-01-21.16:52:00.379>
created_at = <Date 2004-07-26.09:39:38.000>
labels = ['easy', 'docs']
title = 'Enclosing Scope missing from namespace in Tutorial'
updated_at = <Date 2008-01-21.16:52:00.378>
user = 'https://bugs.python.org/brianvanden'

bugs.python.org fields:

activity = <Date 2008-01-21.16:52:00.378>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2008-01-21.16:52:00.379>
closer = 'georg.brandl'
components = ['Documentation']
creation = <Date 2004-07-26.09:39:38.000>
creator = 'brianvanden'
dependencies = []
files = []
hgrepos = []
issue_num = 997912
keywords = ['easy']
message_count = 3.0
messages = ['60540', '60541', '61411']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'brianvanden']
pr_nums = []
priority = 'low'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue997912'
versions = ['Python 2.6']

@brianvanden
Copy link
Mannequin Author

brianvanden mannequin commented Jul 26, 2004

In the docs to Python 2.3.4 (#53, May 25 2004,
21:17:02), Section 4.6 of the Python Tutorial says:

The execution of a function introduces a new symbol
table used for the local variables of the function.
More precisely, all variable assignments in a function
store the value in the local symbol table; whereas
variable
references first look in the local symbol table, then
in the global symbol table, and then in the table of
built-in names. Thus, global variables cannot be
directly assigned a value within a function (unless
named in a
global statement), although they may be referenced.

This doesn't make it clear that in the following sort
of case, the nested def can 'see' the varriables in the
topmost function:

>>> spam = 1
>>> def foo():
	spam = 2
	ham = 3
	def bar():
		print spam, ham
	bar()

	
>>> foo()
2 3

I suggest the following ammendment:

. . . whereas variable references first look in the
local symbol table, then in the local scope of the
enclosing function defs (if any), then in the global
symbol table, . . .

Thanks,

Brian vdB

@brianvanden brianvanden mannequin added docs Documentation in the Doc dir labels Jul 26, 2004
@brianvanden
Copy link
Mannequin Author

brianvanden mannequin commented Jul 26, 2004

Logged In: YES
user_id=1015686

Hi,

I'm new to SF. I meant the e.g. to read like:

>>> spam = 1
>>> def foo():
....spam = 2
....ham = 3
....def bar():
........print spam, ham
....bar()

>>> foo()
2 3

(where '.' are spaces.)

Thanks,

brian

@birkenfeld
Copy link
Member

Fixed in r60158.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir easy
Projects
None yet
Development

No branches or pull requests

2 participants