I didn't understand the file structure and operation of with open
Location of sample.py Python → robot → hello → sample.py
Location of hello.txt Python → robot → templates → hello.txt
sample.py
#Include some code for the class
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()
You can do it if you use "../" well
Recommended Posts