python - How can I avoid this "variable referenced before assignment"? -


ran following problem. it's simple solution, , has been asked here before, couldn't find it.

def a():     lia = []     def b():         in lia:             += 1         lib = generatelist()         in lib:             -= 1         lia = lib      def generatelist():         return [1,2,3,4]      b()  a() 

unboundlocalerror: local variable 'lia' referenced before assignment

lia variable in b() function never initialized.

so, should edit code in followed way:

def a():     lia = []     def b(lia):         in lia:             += 1         lib = generatelist()         in lib:             -= 1         lia = lib      def generatelist():         return [1,2,3,4]      b(lia)  a() 

hope helped you!


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -