Jump to content

Python initialize value

NLBUURMAN
Go to solution Solved by Timotheus2,

You have to declare global variables in each function you want to use it in. It is generally not a good idea to use global variables, try to find a better solution.

Tint = 0

def some_func():
	global Tint
	Tint += something

 

Hi!

I am trying to do some programming, but I am not very experienced, and my googling didn't help.

for a control loop I need an integrator, the variable Tint. in my function I have it defined as Tint += T2error (the error I want to add)

Though running the script gives the error that Tint is not defined or it is mentioned before assignment when I do a little restructuring.

in my __init__ part I created a global called Tint = 0, though it didnt help. any suggestions?

Link to comment
Share on other sites

Link to post
Share on other sites

You have to declare global variables in each function you want to use it in. It is generally not a good idea to use global variables, try to find a better solution.

Tint = 0

def some_func():
	global Tint
	Tint += something

 

My boring Github   /人◕ ‿‿ ◕人\

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×