with openのファイル構造、操作がよくわからなかった
sample.pyの場所
Python → robot → hello → sample.py
hello.txtの場所
Python → robot → templates → hello.txt
sample.py
#クラスの一部コードを記載
def hello(self):
with open("../templates/hello.txt", encoding="utf-8") as f:
t = string.Template(f.read())
contents = t.substitute(robot_name = self.name)
print(contents)
user_name = input()
「../」を上手く使えばできる