翻译:《实用的Python编程》03_05_Main_module (2)

请修改 pcost.py 文件,添加一个类似的 main() 函数。

>>> import pcost >>> pcost.main(['pcost.py', 'Data/portfolio.csv']) Total cost: 44671.15 >>> 练习 3.16:编写脚本

请修改 report.py 和 pcost.py 程序,以便它们在命令行上可以作为脚本执行:

bash $ python3 report.py Data/portfolio.csv Data/prices.csv Name Shares Price Change ---------- ---------- ---------- ---------- AA 100 9.22 -22.98 IBM 50 106.28 15.18 CAT 150 35.46 -47.98 MSFT 200 20.89 -30.34 GE 95 13.48 -26.89 MSFT 50 20.89 -44.21 IBM 100 106.28 35.84 bash $ python3 pcost.py Data/portfolio.csv Total cost: 44671.15

注:完整翻译见 https://github.com/codists/practical-python-zh

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpzwzs.html