I'm rather new to Python and trying to create several different definitions that run each other and refer to different variables in each. Could someone help me as to why this code doesn't work like this and what I need to change to make it work?
From what I thought, it defined what the variable testing
was in the test1
definition and then it would pull that in the test2
and run in the run_this
...
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def test1():
... testing = 1
...
>>> def test2():
... print testing
...
>>> def run_this():
... test1()
... test2()
...
>>> run_this()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in run_this
File "<stdin>", line 2, in test2
NameError: global name 'testing' is not defined
>>>