How to read txt file and put value to the python input

1

Hello, my problem is that I do not know how to do so that when reading the file the values enter the input as an option, the file.txt I put it in the same folder of the program for now I can read files but I can not do that their content are input values.

def leer():

archivo =open("leer.txt","r")
comando=archivo.readline()
while comando !="":
    print comando
    comando=archivo.readline()
archivo.close()


iniciar=0
while True:
     leer()
     comando = raw_input("Escriba help o introduzca una acción: ")
     comando = comando.lower()
     if(comando=="help"):
        print "Hola mundo"

    elif(comando=="Genero"):
        print "Dewey hola"

    elif(comando=="comandos"):
        print "comandos hola"
    else:
        print "Comando no valido"
    
asked by Pablo Manrique Nieto 10.05.2018 в 15:34
source

1 answer

1

Actually you must first make the variable comando look in the whole program, because there you have 2 variables comando one in reading that loads the data in the file and another in the main body, once that you make it "publish" you have to take out the assignment you make with raw_input in the command variable, because you are rewriting them in value. Greetings.

    
answered by 10.05.2018 / 19:46
source