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

local var in "for v in iter" modify the uplevel var value. #72221

Closed
zaazbb mannequin opened this issue Sep 9, 2016 · 2 comments
Closed

local var in "for v in iter" modify the uplevel var value. #72221

zaazbb mannequin opened this issue Sep 9, 2016 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@zaazbb
Copy link
Mannequin

zaazbb mannequin commented Sep 9, 2016

BPO 28034
Nosy @bitdancer, @zaazbb

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 = None
closed_at = <Date 2016-09-09.02:20:14.626>
created_at = <Date 2016-09-09.02:15:37.529>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'local var in "for v in iter" modify the uplevel var value.'
updated_at = <Date 2016-09-09.02:20:14.616>
user = 'https://github.com/zaazbb'

bugs.python.org fields:

activity = <Date 2016-09-09.02:20:14.616>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2016-09-09.02:20:14.626>
closer = 'r.david.murray'
components = ['Interpreter Core']
creation = <Date 2016-09-09.02:15:37.529>
creator = 'zaazbb'
dependencies = []
files = []
hgrepos = []
issue_num = 28034
keywords = []
message_count = 2.0
messages = ['275233', '275234']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'zaazbb']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue28034'
versions = ['Python 3.5']

@zaazbb
Copy link
Mannequin Author

zaazbb mannequin commented Sep 9, 2016

eg:

s = 'aaa'
print(s)
for s in '111', '222', '333':
    print(s)
print(s)

the right result should be:
'aaa'
'111'
'222'
'333'
'aaa'

but, i got:
'aaa'
'111'
'222'
'333'
'333'

the local var in "for v in iter", modify the uplevel var value.
Is it wrong?

@zaazbb zaazbb mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Sep 9, 2016
@bitdancer
Copy link
Member

No, that's the way python works. A for loop does not have its own scope.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant