Ich schreibe ein Skript in Python, um eine neue Zeile zu schreiben und dann die Zeile mit einem Komma und einem String-Label anzufügen. Hier ist das Stück Code.Jede Zeile mit Komma und Label anhängen
new = open(newpath + "/" + "train" + ".txt", 'w')
for idx, tr in enumerate(train_data):
new.write(train_data[idx] + ' , ' + str(index)
Ausgang ist als
Recommendations, thoughts, tips and tricks, or peanuts on moving from wordpress to django
, 1Wordpress [caption] processing
, 1Wordpress: query all images in a posts media library
Komma folgen und Etikett auf der Linie angehängt wird, aber es bewegt sich in die nächste Zeile.
Ich brauche es wie folgt:
Recommendations, thoughts, tips and tricks, or peanuts on moving from wordpress to django , 1
Wordpress [caption] processing , 1
Wordpress: query all images in a posts media library , 1
Können Sie 'print (repr (train_data [idx]))' und sehen, ob am Ende ein '\ n' Zeichen steht? – MooingRawr
yeah, danke für den Tipp, es gibt eine neue Zeile in 'train_data' @MooingRawr – cpwah