Here's an example on what I'm thinking:
def check_args():
if len(sys.argv) < 2:
sys.exit('Reason')
if not os.path.exists(sys.argv[1]):
sys.exit('ERROR: Folder %s was not found!' % sys.argv[1])
global path
path = sys.argv[1]
As you can tell after check_args() completes succefully the "path" variable has universal meaning - you can use it in other functions as de-facto variable.
So I'm thinking if there is a way to access "path" e.g. check_args.path?
How about in python v3?
argparseis the most recent one to be included with python).pathvariable by defining it somewhere near the top of your module. You can store it as an attribute of a function as in @lanzz's answer, but that's almost the same thing since your function is a global module object.