我一直在处理这部分代码,试图得到一个possitive,但无法得到一个。一段时间后发现我的函数“if open in open('users.txt'):”并不是要识别字符串的一部分,因为如果users.txt只包含单词“博拉”。 我的意思是,如果我在user.txt中写入“Bola”,它会给我一个错误。 我设法了解问题,但不知道如何解决它。 使用U.find()尝试,但它并没有提前python:if open in open(example.txt)not reading the string
U=open('users.txt','a+')
bola = "Bola"
if bola in open('users.txt'):
U.close()
print("usercid found")
else:
U.write("[" + str(cid) + "]"+str(m.from_user.first_name)+"\n")
U.close()
print("no usercid gaaaaa")
简单地说:你从来没有真正读取文件。首先,无论你喜欢什么方式。 – TigerhawkT3