Skip to content

Magenaut

  • Home
  • Topics
    • Notes
    • Tutorial
    • Bug fixing
    • Extension
    • Server
  • Q&A
  • Privacy Policy
  • About

scope

Python 3: UnboundLocalError: local variable referenced before assignment

August 22, 2022 by Magenaut

The following code gives the error UnboundLocalError: local variable ‘Var1’ referenced before assignment: Var1 = 1 Var2 = 0 def function(): if Var2 == 0 and Var1 > 0: print("Result One") elif Var2 == 1 and Var1 > 0: print("Result Two") elif Var1 < 1: print("Result Three") Var1 =- 1 function() How can I fix … Read more

Categories Python, Q&A Tags python, python-3.x, scope Leave a comment

Scoping in Python ‘for’ loops

August 21, 2022 by Magenaut

I’m not asking about Python’s scoping rules; I understand generally how scoping works in Python for loops. My question is why the design decisions were made in this way. For example (no pun intended):

Categories Python, Q&A Tags python, scope Leave a comment

Scope of python variable in for loop

August 21, 2022 by Magenaut

Here’s the Python code I’m having problems with:

Categories Python, Q&A Tags for-loop, python, scope Leave a comment

What’s the scope of a variable initialized in an if statement?

August 20, 2022 by Magenaut

I’m new to Python, so this is probably a simple scoping question. The following code in a Python file (module) is confusing me slightly:

Categories Python, Q&A Tags if-statement, local-variables, python, scope, variables Leave a comment

Explaining the ‘self’ variable to a beginner

August 20, 2022 by Magenaut

I don’t immediately grok what self is pointing to. This is definitely a symptom of not understanding classes, which I will work on at some point.

Categories Python, Q&A Tags class, oop, python, scope Leave a comment

How to access outer class from an inner class?

August 19, 2022 by Magenaut

I have a situation like so…

Categories Python, Q&A Tags inner-classes, nested, python, scope Leave a comment

Why does assigning to my global variables not work in Python?

August 19, 2022 by Magenaut

I’m having terrible trouble trying to understand python scoping rules.

Categories Python, Q&A Tags global-variables, python, scope Leave a comment

Python nested functions variable scoping

August 18, 2022 by Magenaut

“global name ‘_total’ is not defined”

Categories Python, Q&A Tags python, scope, variables Leave a comment

Block scope in Python

August 18, 2022 by Magenaut

When you code in other languages, you will sometimes create a block scope, like this:

Categories Python, Q&A Tags python, scope Leave a comment

Python: load variables in a dict into namespace

August 17, 2022 by Magenaut

I want to use a bunch of local variables defined in a function, outside of the function. So I am passing x=locals() in the return value.

Categories Python, Q&A Tags locals, python, scope, variables Leave a comment
Older posts
Newer posts
← Previous Page1 Page2 Page3 … Page5 Next →
  1. michealSmith07 on Is there a way to dynamically refresh the less command?August 21, 2022

    That is a very nice post. I like this post.

  2. anonymous on Fix libwacom9 dependency issue when upgrade DebianJune 27, 2022

    saved my day!! Thanks for the help…

  3. sreedhar on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    Thanks its working

  4. saintnick on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    remove libwacom2 worked for me as well

  5. ranafoul on Fix libwacom9 dependency issue when upgrade DebianApril 22, 2022

    apt remove libwacom2 helped on kali 2022.01. gr8

.net ajax asp.net asp.net-core asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-web-api bash c# command-line css custom-post-types custom-taxonomy dataframe dictionary django entity-framework functions gridview html iis javascript jquery json linux list matplotlib numpy pandas php plugin-development plugins posts python python-2.7 python-3.x security shell shell-script sql string vb.net webforms wp-query

© 2026 Magenaut • Built with GeneratePress