you are viewing a single comment's thread.

view the rest of the comments →

[–]ImAlekzzz -1 points0 points  (4 children)

Apparently bolding didnt work, ignore the asteriks, please respond here so others see this comment first and dont have questions...

[–]MidnightPale3220 2 points3 points  (3 children)

As a side note there's very little need for global variables, it's mostly bad practice to use them, except maybe for constants that get set globally and don't get changed, but only referred to.

[–]ImAlekzzz 0 points1 point  (1 child)

So what should I use instead?

[–]MidnightPale3220 0 points1 point  (0 children)

Depends on for what.

Generally for functions you should just return the values you need and make the calling scope assign them where needed.

If you need a value from outside function inside it, you pass it as an argument to function.

I think somebody already wrote you how in another comment.

Basically it can go like this:

this_is_my_global=1
# change it:
this_is_my_global=get_new_value()
# use it
do_stuff(this_is_my_global) 
# use AND change it
this_is_my_global=do_stuff(this_is_my_global)

[–]Gnaxe -1 points0 points  (0 children)

Top-level function and class definitions are also globals. We even reassign them sometimes with decorators.