Files

1.1 KiB

id, source_exercise_id, title, section, source_path, source_repo, source_commit, student_visible_solution, has_private_solution, skip
id source_exercise_id title section source_path source_repo source_commit student_visible_solution has_private_solution skip
practical-python-4.9 4.9 Better output for printing objects 4.3 Special Methods 04_Classes_objects/03_Special_methods.md https://github.com/dabeaz-course/practical-python 93dca856b41c61a0a0f85ae334116e4c125629ea false false false

Exercise 4.9: Better output for printing objects

Source: Practical Python Programming, 04_Classes_objects/03_Special_methods.md.

Exercise 4.9: Better output for printing objects

Modify the Stock object that you defined in stock.py so that the __repr__() method produces more useful output. For example:

>>> goog = Stock('GOOG', 100, 490.1)
>>> goog
Stock('GOOG', 100, 490.1)
>>>

See what happens when you read a portfolio of stocks and view the resulting list after you have made these changes. For example:

>>> import report
>>> portfolio = report.read_portfolio('Data/portfolio.csv')
>>> portfolio
... see what the output is ...
>>>

关联来源