我正在写一个基本程序来用西班牙语修饰动词。我目前有两个文件:main.py和test.py。我正在使用test.py来测试功能。
当前main.py具有:
"before read"
最后,我尝试调用test.py上的testt函数 test.py具有:
import test as present
print("Welcome to Spanish Verb Conjugator")
verb = raw_input("Enter the verb: ")
length = len(verb)
#print(length)
v1 = length - 2
r1 = length - 1
v = verb[v1]
r = verb[r1]
end = str(v+r)
stem = verb[0:v1]
tense = raw_input("Choose your tense: ")
if tense == "present":
test.testt(end)
我的错误是:
import main
def testt(ending):
if ending == "ar":
form = raw_input("Form: ")
if form == "yo":
return form + " " + stem + "o"
我正在使用python 2。
答案 0 :(得分:1)
将main.py中的代码更改为:
import test
print("Welcome to Spanish Verb Conjugator")
verb = raw_input("Enter the verb: ")
length = len(verb)
#print(length)
v1 = length - 2
r1 = length - 1
v = verb[v1]
r = verb[r1]
end = str(v+r)
print end
stem = verb[0:v1]
tense = raw_input("Choose your tense: ")
if tense == "present":
test.testt(end)
并将test.py更改为:
def testt(ending):
if ending == "ar":
form = raw_input("Form: ")
if form == "yo":
return form + " " + stem + "o"
此外,
stem
在test.py
中定义的main.py
中将不起作用
答案 1 :(得分:0)
您正在将test
导入为present
。不要使用test.testt()
,而要使用present.testt()
。此外,您的代码还存在circular import
问题。 Circular Import Problem