I want to read the input.txt line by line and send that as a request to the server and later save the response respectively. how to read and write the data line by line ? my code below works for just one input within input.txt (ex : I am Hungry). Can you please help me how to do it for multiple input ? I did as below. now throwing an error as : File "tts.py", line 198, in TEXT_TO_READ["tts_input"] = line TypeError: 'str' object does not support item assignment
my code :
TEXT_TO_READ = """{
"tts_type": "text",
"tts_input": "DUMMY"
}"""
TEXT_TO_READ = json.loads(TEXT_TO_READ)
scriptPath = os.path.abspath(__file__)
scriptPath = os.path.dirname(scriptPath)
fileInput = os.path.join(scriptPath, "input.txt")
try:
content = open(fileInput, "r")
except IOError:
print "error message"
Error_Status = 1
sys.exit(Error_Status)
for line in content.readlines():
if len(line):
TEXT_TO_READ["tts_input"]=line.strip('\n')
TEXT_TO_READ = json.dumps(TEXT_TO_READ)
print TEXT_TO_READ
request = Request()