I wasnt able to reproduce your error, best I could to mimic your code is posted below
not sure is doing what you expected from your code
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
with open("songs.txt","r") as filesongs:
songs=filesongs.read()
ix=0
for i in songs:
if i =='
':
ix += 1
else:
ix=ix
print('
number of lines in songs.txt : ',ix)
filesongs.close()
random=random.randint(0,ix)
print('
random number betwen 0 and lines in songs.txt : ',random)
with open("songs.txt","r") as ransong:
pippo = []
for i in ransong.readlines():
i=i.replace('
','')
pippo += i
# print('
all the lines in songs.txt as list : ',pippo)
print('
random line in songs.txt : ',pippo[random])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…