Okay, I am confused on the global statement. To my knowledge it lets you easily access variables from a function to be used in the session. Now someone said that it's useless and you shouldn't use it in your code. Is this true?
AutoPython
5
Junior Poster
Recommended Answers
Jump to PostThe global statement allows you to break a variable out of the function scope it'd normally be contained in if you just defined it in a function. The "Global variables are evil" paradigm says that anything to do with a global is inherently evil, and that class scope should usually …
Jump to PostAs your code gets more complex and longer, a function could change the value of the global variable and make your code buggy. This kind of bug might be hard to figure out! Now your life has just been made a lot harder!
Jump to PostWell, I always set the global variables in the function to a new variable, then delete the original global variable. So then would the new variable (outside the function) inherit the global trait?
Can you give us an example?
Jump to Post1. Does c1 inherit the global trait, or remain local
2. Does the global trait remained assigned to a variable named c, or would deleting the variable also delete the global statement.There is nothing special with a global variable. The statement
global c
in testfunc only means that …
All 16 Replies
JugglerDrummer
0
Junior Poster
AutoPython
5
Junior Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
AutoPython
5
Junior Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
AutoPython
5
Junior Poster
Gribouillis
1,391
Programming Explorer
Team Colleague
sneekula
969
Nearly a Posting Maven
jice
53
Posting Whiz in Training
AutoPython
5
Junior Poster
Stefano Mtangoo
455
Senior Poster
snippsat
661
Master Poster
jice
53
Posting Whiz in Training
AutoPython
5
Junior Poster
Gribouillis
1,391
Programming Explorer
Team Colleague
AutoPython
5
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.