Skip to content

Commit aa6d068

Browse files
author
Oliver
committed
ex2_3 pythonic thinking to print using a list generator that's converted to a tuple and used with a print statement
1 parent 40241ac commit aa6d068

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ex3_2.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import stock
2+
import tableformat
3+
p = stock.read_portfolio('Data/portfolio.csv')
4+
tableformat.print_table(p, ['name', 'shares', 'price'])

tableformat.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def print_table(data, headers):
2+
print('%10s' * len(headers) % tuple(key for key in headers))
3+
print(('-'*10 + ' ')* len(headers))
4+
for item in data:
5+
print('%10s' * len(headers) % tuple(getattr(item, h) for h in headers))

0 commit comments

Comments
 (0)