Global variables seem to draw the scorn if not ire of most python developers, and recently I've been faced with a situation where creating a variable in a series of defs needs to be passed back to main(). I did a little searching with my friend and associate Dr. Google and found a stack over flow thread which gave me an idea.
In the script I'm (re) writing, I'd like to follow the form of defining my defs() and then calling them from main(). However, each of my defs() use a try/except block, and if there is an exception anywhere along the line I need to abort the final processing.
This is what I came up with in concept:
errorList = 
#some other code
if len(errorList) == 0:
# final operations
# don't execute final operations
Pretty simple concept right?
Taking it one step further, I started thinking how about this:
def1List = 
def2List = 
# blah2 blah2
if def1List == myTargetValue:
elif defList == myOtherTargetValue:
do something else...
myValue = def2List
myOtherValue = def2List
# use myValue and MyOtherValue as I need to...
These look like they'll work for me in a number of different applications, but I'd like to here from you (and you know who you are) as to whether or not these are:
Something everybody does already