스페인어 동사를 사용할 스크립트를 Python으로 작성하려고합니다. 이것은 파이썬으로 처음 스크립팅 한 것이므로 간단한 실수 일 수 있습니다. 내가 스크립트, I 입력 "요 tener"를 실행하고 오류가 발생하는 경우 : NameError : name ''이 (가) 정의되지 않았습니다.
-
Traceback (most recent call last): File "", line 13, in File "", line 1, in NameError: name 'yo' is not defined
eval()
기능을 사용 http://pythonfiddle.com/#sthash.bqGWCZsu.dpuf# Input pronoun and verb for conjugation. text = raw_input() splitText = text.split(' ') conjugateForm = eval(splitText[0]) infinitiveVerb = eval(splitText[1]) # Set the pronouns to item values in the list. yo = 0 nosotros = 1 tu = 2 el = 3 ella = 3 usted = 3 # Conjugations of the verbs. tener = ["tengo", "tenemos", "tienes", "tiene", "tienen"] ser = ["soy", "somos", "eres", "es", "son"] estar = ["estoy", "estamos", "estas", "esta", "estan"] # List of all of the infinitive verbs being used. Implemented in the following "if" statement. infinitiveVerbs = [tener, ser, estar] # Check to make sure the infinitive is in the dictionary, if so conjugate the verb and print. if infinitiveVerb in infinitiveVerbs: print("Your conjugated verb is: " + infinitiveVerb[conjugateForm])
또한 'eval'은 보안상의 위험이 있습니다. 사용자가'os.system ('/ home/hack.sh')'을 프로그램의 입력으로 입력하면 어떻게 될지 생각해보십시오. – tripleee