Skip to content

Magenaut

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

scope

Python scope: “UnboundLocalError: local variable ‘c’ referenced before assignment”

August 17, 2022 by Magenaut

I am trying to figure out this: c = 1 def f(n): print c + n def g(n): c = c + n f(1) # => 2 g(1) # => UnboundLocalError: local variable 'c' referenced before assignment Thanks! Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may … Read more

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

Advanced Nested List Comprehension Syntax

August 16, 2022 by Magenaut

I was playing around with list comprehensions to get a better understanding of them and I ran into some unexpected output that I am not able to explain. I haven’t found this question asked before, but if it /is/ a repeat question, I apologize.

Categories Python, Q&A Tags list-comprehension, python, scope, syntax Leave a comment

Python overwriting variables in nested functions

August 16, 2022 by Magenaut

Suppose I have the following python code:

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

How to create module-wide variables in Python?

August 15, 2022 by Magenaut

…
UnboundLocalError: local variable ‘DBNAME‘ referenced before assignment
…

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

Global dictionaries don’t need keyword global to modify them?

August 15, 2022 by Magenaut

It would be impossible to assign to a global variable without global.

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

String with ‘f’ prefix in python-3.6

August 14, 2022 by Magenaut

I’m trying out Python 3.6. Going through new code, I stumbled upon this new syntax:

Categories Python, Q&A Tags f-string, python, python-3.6, scope, string-formatting Leave a comment

Creating a class within a function and access a function defined in the containing function’s scope

August 14, 2022 by Magenaut

Edit:

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

Python – Why is this class variable not defined in the method?

August 14, 2022 by Magenaut

I have a python application which is as follows:

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

How can a function access its own attributes?

August 13, 2022 by Magenaut

is it possible to access the python function object attributes from within the function scope?

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

Tensorflow: How to get a tensor by name?

August 13, 2022 by Magenaut

I’m having trouble recovering a tensor by name, I don’t even know if it’s possible.

Categories Python, Q&A Tags python, scope, tensorflow Leave a comment
Older posts
Newer posts
← Previous Page1 Page2 Page3 Page4 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