Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do in Python
#3
Would only do the last item in list of 'expenses-18'. Need to loop thru file.

expenses-18

010118,1,1.00,1
020218,2,2.22,2
030318,3,33.33,3
040418,4,44.44,4
#!/usr/bin/python
num_lines = sum(1 for line in open('expenses-18'))
print ' \n'
print "file line count :",  num_lines
print ' \n'
# file = open('expenses-18', 'r')
with open('expenses-18', 'r') as file:
  for line in file:
      pdate, catg, amt, howp = line.split(",")
print line
print 'pdate :', pdate
print 'catg  :', catg
print ' amt  :', amt
print 'howp  :', howp
print ' ##\n'
file.close()
Reply


Messages In This Thread
How to do in Python - by oldcity - Apr-26-2018, 03:20 PM
RE: How to do in Python - by nilamo - Apr-26-2018, 03:45 PM
RE: How to do in Python - by oldcity - Apr-27-2018, 03:07 PM
RE: How to do in Python - by nilamo - Apr-27-2018, 03:22 PM
RE: How to do in Python - by oldcity - May-24-2018, 03:53 PM
RE: How to do in Python - by snippsat - May-24-2018, 06:22 PM
RE: How to do in Python - by nilamo - May-24-2018, 06:39 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020