Importing an output from another function

Byte eoinrogers at gmail.com
Fri Mar 17 15:15:28 EST 2006


Probably a stupid question, but I'm a newbie and this really pisses me
off. Run this script:

import random

def Func1():
    choice = ('A', 'B', 'C')
    output = random.choice(choice)

def Func2():
    print output

Func1()
Func2()

And: an error message...... It says:

Traceback (most recent call last):
  File "ptls-demo.py", line 11, in ?
    Func2()
  File "how -the-hell-do-i-fix-this.py", line 8, in Func2
    print output
NameError: global name 'output' is not defined

Obviosly, I need to import the variable 'output' from Func1() into
Func2(), but how?

Thanks in advance,
 -- /usr/bin/byte




More information about the Python-list mailing list