0

Hey guys.

I'm having some trouble with this error.

class App():
	i = 0
	def updateCount(self):
		i = i +1
	
app = App()
app.updateCount()

input('Enter')

I have tried global i but get an error 'global name i is not defined'.

Can someone clue me in? Cheers :D

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Gribouillis
2

As you wrote your class, i is a static variable (a class member and not an instance member). You can update it with App.i += 1

Votes + Comments
nice and helpful
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.