forked from flypythoncom/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard.py
More file actions
33 lines (30 loc) · 780 Bytes
/
card.py
File metadata and controls
33 lines (30 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def safe_float(obj):
try:
retval = float(obj)
except (ValueError,TypeError),diag:
retval = str(diag)
return retval
def main():
log = open("cardlog.txt","w")
try:
ccfile = open("carddata.txt","r")
except IOError,e:
log.write("no txns this \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):
total += result
log.write("data ....processed\n")
else:
log.write("ignored: %s" % result)
print "$%.2f (new balance)" % (total)
log.close()
if __name__ == '__main__':
print "run"
main()