Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Python模块/导入数据?_Python 2.7_Variables_Import_Module - Fatal编程技术网

Python 2.7 Python模块/导入数据?

Python 2.7 Python模块/导入数据?,python-2.7,variables,import,module,Python 2.7,Variables,Import,Module,我有两个python文件正在使用 在cryp.py中,我有: def test(): test = raw_input("> ") import cryp What is your name? cryp.test print "To be sure your name is: " + test 在cryptek.py中,我有: def test(): test = raw_input("> ") import cryp What is your name? cr

我有两个python文件正在使用

在cryp.py中,我有:

def test():
    test = raw_input("> ")
import cryp
What is your name?
cryp.test
print "To be sure your name is: " + test
在cryptek.py中,我有:

def test():
    test = raw_input("> ")
import cryp
What is your name?
cryp.test
print "To be sure your name is: " + test
它的错误是“test未定义”,我如何使它从cryp.py获取测试变量?

(我有Python 3.6.1),所以我解决了它,但并没有完全按照您的要求解决。希望这能给你一个开始:

克里特克:

from cryp import *
print("To be sure your name is: " + test)
cryp:

工作完美。问题在于这些定义是从哪里来的


您是否需要此选项来处理定义?

这里有多个问题。您添加了
import
语句。test()函数需要返回一些内容。如果不是,它将返回
None
。另外,
cryp.test
是一个函数对象,而
cryp.test()
是对函数的调用

问题中没有的错误消息说明了这一点

Traceback (most recent call last):
  File "cryptek.py", line 4, in <module>
    print "To be sure your name is: " + cryp.test()
TypeError: cannot concatenate 'str' and 'NoneType' objects
cryptek.py

import cryp
print "What is your name?"
cryp.test
print "To be sure your name is: " + cryp.test()

C:>python cryptek.py
What is your name?
> asdf
To be sure your name is: asdf

你试过导入cryp吗?是的,我已经在顶部导入了cryp,我将在Python中的保留关键字中编辑它。我不确定,我还试过pizza这个词来确保,同样的问题我相信test是保留关键字。但不能保证这是正确的。顺便说一句,比萨饼是最好的。我试过gmons,它仍然会给我“测试未定义”我使用导入cryp。这些帖子有帮助吗?不,实际上没有。在发布这个问题之前,我已经看过了,因为这在技术上是一条规则。明白了。我将帮助您解决这个问题,但可能要等到一天结束,因为我现在正在工作。无论采用哪种方式编码,解决问题通常都需要一点时间,所以我通常会慢慢来,不着急:p添加此项后,它现在会两次提示我test=raw\u input(“>”),这意味着我必须输入两次名称才能继续。\u这不是我的错误。。。这是我的错误`回溯(最近一次调用上次):文件“cryptek.py”,第4行,打印“\n要确定,您的名字是:“+name name错误:name‘name’未定义”`@TheCryptek-对不起,是的,您收到了错误消息。
无法连接
消息是下一条消息,直到
()
被添加到
测试
以使其成为函数调用。我将其命名为cryp.test(),我不担心无法连接的错误,我可以轻松修复,现在我正在尝试解决当前的easy,从cryp.py中提取测试