问题描述
可能是一个愚蠢的问题,但我是一个新手,这真让我感到生气
off。运行这个脚本:
随机导入
def Func1():
choice =(''A' ',''B'',''C'')
输出= random.choice(选择)
def Func2():
打印输出
Func1()
Func2()
并且:出现错误信息......它说:
Traceback(最近一次调用最后一次):
文件" ptls-demo.py",第11行, in?
Func2()
文件" how -the-hell-do-i-fix-this.py,第8行,在Func2中
打印输出
NameError:全局名称''输出''未定义
显然,我需要导入变量''output' '从Func1()进入
Func2(),但是如何?
提前致谢,
- / usr / bin / byte
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
这篇关于从另一个函数导入输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!