So Im trying to follow users, but the problem is that it works on every user except the last one that I have in my to_follow.txt:
Chile_Temblores
Aguas_Antof
costaneranorte_
onemichile
Edelaysen
Chilquinta600
CGE_Clientes
Frontel_
EnelClientesCL
javi1597
The code that Im using is the following:
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()
So when I print what is happening, it stops in javi1597 and it does not exit de execution, Where is the problem?
I think you should have used the variable "accounts" instead of using the file name "to_follow" as a method:
Else I don't understand where the function to_follow() is coming from and why you don't use the created variable "accounts".
Edit: I refactored your code. You don't have to split the file but can directly iterate over the rows with "for in".
Edit 2: When you trying to add the last element "javi1597" it could be possible, that it also contains the "end of file" and it should be removed before you pass it into your API. Only an idea.