Il faudrait que tu fasses des vérifications sur ton texte de tweet avant de le tweeter.
J'ai fait un code exemple :
1 2 3 4 5 6 7 8 9 10
| with open("tweets.txt", "r") as file:
print(file)
lines = file.readlines()
print(lines)
for i, line in enumerate(lines):
print(i, "th line:", line, " length=", len(line))
if len(line) > 140:
print("Error! Line is too long") |
Mon fichiers tweets.txt :
Bonjour pi3dany!
#python rocks!
this is a tweet message
Voici le résultat en console :
"C:\Program Files\Python35\python.exe" C:/Users/X-pigradot/PycharmProjects/TestingSutffs/main.py
<_io.TextIOWrapper name='tweets.txt' mode='r' encoding='cp1252'>
['Bonjour pi3dany!\n', '#python rocks!\n', 'this is a tweet message']
0 th line: Bonjour pi3dany!
length= 17
1 th line: #python rocks!
length= 15
2 th line: this is a tweet message length= 23
Process finished with exit code 0
Partager