I have several txt
files, that contain first and last name of the authors.
Here are two examples among about thirty (that do not contain the same number of authors).
authors1.txt
AU - Jordan, M.
AU - Thomson, J.J.
AU - Einstein, A.
AU - Tesla, N.
authors3.txt
AU - Agassi, A.
AU - Herbert, P.H.
AU - Agut, R.B.
I want to extract the last and first name of the authors for each file. Since I am a beginner in Python, I wrote a script (more or less suitable).
with open('authors3.txt', 'rb') as f:
textfile_temp = f.read()
#o_author1
o_author1 = textfile_temp.split('AU - ')[1]
L_name1 = o_author1.split(",")[0]
F_name1 = o_author1.split(",")[1]
print(L_name1)
print(F_name1)
#o_author2
o_author2 = textfile_temp.split('AU - ')[2]
L_name2 = o_author2.split(",")[0]
F_name2 = o_author2.split(",")[1]
print(L_name2)
print(F_name2)
#o_author3
o_author3 = textfile_temp.split('AU - ')[3]
L_name3 = o_author3.split(",")[0]
F_name3 = o_author3.split(",")[1]
print(L_name3)
print(F_name3)
my result is:
Agassi
A.
Herbert
P.H.
Agut
R.B.
My question: Is it possible to write a script with a loop, knowing that the files authors#.txt
, don't each contain the same number of authors?