Feb-13-2019, 01:29 PM
Hi,
I would like to replace a word with a variable in a html file.
My code is:
So if the user add his name, on the html file it should be appear.
For example: YourNameHere should replaced with "John Smith".
The error message:
Traceback (most recent call last):
File "C:/Users/tmate/PycharmProjects/Tesztprojekt/fb.py", line 12, in <module>
s = s.replace('YourNameHere', name)
NameError: name 'name' is not defined
Any suggestion?
Thanks,
Tamas
I would like to replace a word with a variable in a html file.
My code is:
name = raw_input("Name: ") s = open("helloworld.html").read() s = s.replace('YourNameHere', name) f = open("helloworld.html", 'w') f.write(s) f.close()But it is not working..
So if the user add his name, on the html file it should be appear.
For example: YourNameHere should replaced with "John Smith".
The error message:
Traceback (most recent call last):
File "C:/Users/tmate/PycharmProjects/Tesztprojekt/fb.py", line 12, in <module>
s = s.replace('YourNameHere', name)
NameError: name 'name' is not defined
Any suggestion?
Thanks,
Tamas