Hey fellow Python learners, I’m reaching out for some help with a problem that’s been driving me crazy. I’m working on a project where I have a function that calls another function, and that second function calls a third function. The issue is, I’m trying to modify a variable in the first function from the third function, but it’s not working as expected. I’ve been reading about variable scope and nested functions, but I’m still having trouble wrapping my head around it. Can anyone explain how Python resolves variable scope in nested functions, or point me to some resources that can help me understand this better? I’ve tried using the global
keyword, but I’ve heard that’s not the best practice. Any help or advice would be greatly appreciated!
submitted by /u/RecipeNo4290
[link] [comments]
r/learnpython Hey fellow Python learners, I’m reaching out for some help with a problem that’s been driving me crazy. I’m working on a project where I have a function that calls another function, and that second function calls a third function. The issue is, I’m trying to modify a variable in the first function from the third function, but it’s not working as expected. I’ve been reading about variable scope and nested functions, but I’m still having trouble wrapping my head around it. Can anyone explain how Python resolves variable scope in nested functions, or point me to some resources that can help me understand this better? I’ve tried using the global keyword, but I’ve heard that’s not the best practice. Any help or advice would be greatly appreciated! submitted by /u/RecipeNo4290 [link] [comments]
Hey fellow Python learners, I’m reaching out for some help with a problem that’s been driving me crazy. I’m working on a project where I have a function that calls another function, and that second function calls a third function. The issue is, I’m trying to modify a variable in the first function from the third function, but it’s not working as expected. I’ve been reading about variable scope and nested functions, but I’m still having trouble wrapping my head around it. Can anyone explain how Python resolves variable scope in nested functions, or point me to some resources that can help me understand this better? I’ve tried using the global
keyword, but I’ve heard that’s not the best practice. Any help or advice would be greatly appreciated!
submitted by /u/RecipeNo4290
[link] [comments]