Good morning reading I found some examples and then playing with them culminates with this function:
#!/usr/bin/env python3
import sys
def leer(mensaje):
print(mensaje)
entrada = ""
while True:
caracter = sys.stdin.read(1)
if caracter == '\t':
break
entrada += caracter
return entrada
As you can see, what you do is read from the input character by character in search of a tabulation and when you come across the tabulation character, the concatenation of these returns.
It should be noted that the execution remains in the same way pending until
the user presses enter, but only if a tab is found
will come out of the loop.
your code just change the raw_input by the read method:
# -*- coding: utf-8 -*-
import sys
def leer(mensaje):
print(mensaje)
entrada = ""
while True:
caracter = sys.stdin.read(1)
if caracter == '\t':
break
entrada += caracter
return entrada
outfile = open('codehero.txt', 'w') # Indicamos el valor 'w'.
outfile.write(leer("Ingresa lo que deseas agregar : "))
outfile.close()
# Leemos el contenido para comprobar que ha sobreescrito el contenido.
infile = open('codehero.txt', 'r')
print("\n\tEste archivo fue modificado y leido correctamente")
print(infile.read())
# Cerramos el fichero.
infile.close()
Anyway here are useful links: