I am reading a file with some data. I wish to divide the data into several categories and write these into files of their own (for example integers, like phone numbers; decimals; single words; and separate sentences).
def data_reading():
data = []
integers = []
with open("my_lines.txt") as file:
for row in file:
row = row.strip().replace("\n", "")
data.extend(row.split(","))
for values in data:
if values.isnumeric():
print(values + " - integer")
integers.extend(row.split(","))
elif values.isalpha():
print(values + " - alphabetical strings")
elif values.isalnum():
print(values + " - alphanumeric")
else:
print(values + " - float")
return integers
somethin = data_reading()
print(somethin)
If I am to input lines like 123, abc, Address unknown, 20.12.85, I was aiming to get 4 lists to store values and use these to write in the 4 files with separate write functions. However, now I am only storing the last float value as many times as I have lines in the data file I am reading (I was trying to get the numbers with isnumerical()). How come? I seem to be missing something.