I wrote the following code to read out a bill from a file and then putting it into a bills-list.
The bill contains: "company", "customer", Year, Month, Day, Amount, "credit/debit"
Is there a nicer way using list comprehension to make this code look better?
def read_bills(file = "bills.csv"):
"""Read bills from the file system 'bills.csv'"""
# Create a list in which each bill is entered.
bills = []
for line in open(file):
bill = line.strip().split(',')
for i in range(len(bill)):
if i > 1 and i < 5:
bill[i] = int(bill[i].strip())
elif i == 5:
bill[i] = float(bill[i].strip())
else:
bill[i] = bill[i].strip()
bills.append(bill)
return bills