# How to use this script:
#
# Run Python:
#
#   import  pcost  as  p  # It will NOT run main() !!!
#   >>> p.main()
#   >>> p.portfolio_cost('Data/portfolio.csv')
#
# pcost.py
#
# Exercise 1.27

def portfolio_cost(filename):
    with open(filename, 'rt') as inpFile:
        headers = next(inpFile).strip().split(",");
        print(headers)
    
    
        tot_cost = 0
    
        for line in inpFile:
            row = line.strip().split(",")
            print(row)
    
            tot_cost += int(row[1]) * float(row[2])
            print("Cum cost = ", tot_cost)
    
            # Make a dictionary with 2 list (with zip())
            result = zip(headers, row)	# It's an iterable object
            d = dict( result )
            print(d, "\n")

    return tot_cost

def main():
    cost = portfolio_cost('Data/portfolio.csv')
    print('Total cost:', cost)

# *******************************************
# ONLY run main() when executed as a SCRIPT
# Will NOT run main() if IMPORTED !!!
# *******************************************
if __name__ == "__main__":
    main()

