信用卡交易系统 Python
2015-12-06 16:49
543 查看
#!/usr/bin/env python #--*-- coding:utf-8 --*-- #safe_float 的函数主体 def safe_float(obj): 'safe version of float()' try: retval = float(obj) except (ValueError,TypeError),diag: retval = str(diag) return retval def main(): 'handles all the data processing' log = open('cardlog.txt','w') #记录log try: ccfile = open('carddata.txt','r') except IOError,e: log.write('no txns this month\n') log.close() return txns = ccfile.readlines() ccfile.close() total = 0.00 log.write('account log:\n') for eachTxn in txns: result = safe_float(eachTxn) if isinstance(result,float): #检查是否为float total += result log.write('data... processed\n')#写入 else: log.write('ignore:%s'%result) print '$%s.2f (new balance)'%(total) log.close() if __name__ == '__main__': main()
相关文章推荐
- Python中用encoding声明的文件编码和文件的实际编码之间的关系
- python连接postgresql数据库
- Go学习笔记:关于Java、Python、Go编程思想的不同
- python读写文件脚本
- leetcode Maximum Depth of Binary Tree python
- leetcode Minimum Depth of Binary Tree python
- python解析json文件
- 【python】python中的多态与duck typing
- LDA(线性判别分析,Python实现)
- selenium python (九)对话框处理
- leetcode Binary Tree Level Order Traversal python
- Python爬虫实战一之爬取糗事百科段子
- Python/Django 生成二维码
- 零基础入门学习Python(2):字符串输出
- leetcode Invert Binary Tree python
- leetcode Binary Tree Paths python
- python struct中pack和unpack
- selenium python (八)定位frame中的对象
- python处理地理数据-geopandas和pyshp
- python:文本文件处理