with open(filepath,'r') as file:这样就行了你现在的问题是搞不清字符串和变量的区别,还是先搞搞清楚再说复杂的应用。
with open("test.txt", "r", encoding='UTF-8') as f: data = f.read()