elif used_prefix and cmd == "xp":
if self.getAccess(user) >= 1:
f = open("users/" + user.name.lower() + ".txt", 'r')
word = f.readline().split("X Points = ")
if word == "0":
room.message("You have no X Points")
else:
room.message("You Have " + word + " X Points")
f.close()
else:
room.message("You are not whitelisted " + user.name.capitalize())
当我尝试使用 XP 时,它在控制台中显示 Can't conversion 'list' object to strimplicitly
错误。我正在使用 python 3.3。
最佳答案
你可能需要
word = f.readline().split("X Points = ")[1].strip()
当您拆分时,它将返回拆分为列表的项目列表。需要取实际值对应的元素
示例
data = "X Points = 10"
print data.split("X Points = ")
输出
['', '10']
所以,我们需要获取第二个元素。这就是我们使用 [1]
关于python - 无法将 'list' 对象隐式转换为 str python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20374011/