所以我试着跟踪用户,但问题是除了我的to中的最后一个用户外,它对每个用户都有效_follow.txt文件地址:
Chile_Temblores
Aguas_Antof
costaneranorte_
onemichile
Edelaysen
Chilquinta600
CGE_Clientes
Frontel_
EnelClientesCL
javi1597
我使用的代码如下:
def createFriends(api):
accounts = open("to_follow.txt", "r")
friends = api.friends_ids()
print("friends:", friends)
follow = accounts().split('\n')
print (follow)
for account in follow:
if account not in follow:
api.destroy_friendship(account)
for account in follow:
if account not in friends:
print("account: ", account)
fuentes.append(account)
api.create_friendship(account)
print("friendship created")
print(fuentes)
accounts.close()
所以当我打印正在发生的事情时,它会在javi1597中停止,并且不会退出反执行,问题在哪里?你知道吗
我认为您应该使用变量“accounts”,而不是使用文件名“to\u follow”作为方法:
否则,我就不明白follow()的函数是从哪里来的,为什么不使用创建的变量accounts。你知道吗
编辑:我重构了你的代码。您不必拆分文件,但可以使用“for in”直接遍历行。你知道吗
编辑2:当您试图添加最后一个元素“javi1597”时,它可能还包含“文件结尾”,在您将其传递到API之前应该将其删除。只是个主意。你知道吗
相关问题 更多 >
编程相关推荐