2016-08-30 62 views
0

我目前正在尝试在Python中使用两个模块,我试图让一个模块接受用户输入并将其存储。但我不知道如何从输入模块中检索数据。我已经导入了所有内容,但这只能从输入模块中的def再次运行我的输入。以下是我的输入模块的一个例子。如何从用户返回这个值并在我的其他模块中使用它来进行计算?用户输入并在Python中检索它

def test(): 
    test = int(input("numbers:")) 
    return test 
+2

需要更具体。其他模块是什么样的,哪些不起作用? – Xiaoerge

+1

python 2或3? – depperm

+0

不太清楚你的意思。什么是:*“这只能从输入模块中的def再次运行我的输入”*?该代码让它应该做什么('python3'),但我建议你应该决定如何处理不正确的输入。 –

回答

3

我假设你的意思是你使用两个文件,并且你需要使用另一个文件上测试函数的信息。然后,假设你测试的文件名是testfile.py,我会去:

import testfile 
num = testfile.test() # This will store the number recieved in the test() function in the variable num 
print('Recieved number from user:', num) 
相关问题