I have a hello.py file which asks user for their name and prints them a welcome message.
import subprocess
filename = "hello-name.txt"
fout = open("out.txt", "w")
with open(filename, "r+") as f:
lines = f.readlines()
your_name = input("What is your name? ")
title_name = your_name.title()
for line in lines:
line = fout.write(line.replace("[Name]", your_name))
line = fout.write(line.replace("[Title]", title_name))
print(line.strip())
subprocess.call(["notepad.exe", "out.txt"])
This is the content of my hello-name.txt file
Hello [Name]
Welcome to the world [Title]
My Question
When run hello.py it asks user for their Name and as soon as the name is entered, Python gives the following error :
line = fout.write(line.replace("[Title]", title_name))
AttributeError: 'int' object has no attribute 'replace'
Kindly help me to fix this issue.
Thank You