By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

I'm having trouble formatting text from a .txt file, into a grid.

P: 1
Im trying to create a bank statement basically, and Im having trouble formatting the output to a grid, from a .txt file. And I wrote the file, and can read the first line, and want to pull the date out, and seperate the amount. And with the following lines say the date, type of transaction, the location, amount of the transaction, and finally the running total.

here is what I'm looking to achieve with this:(with all the numbers and columns lining up with plenty of space for the characters.)

03/15/11 Beginning Balance 1000.00
03/15/11 Check Hugos 25.00 975.00
03/15/11 Deposit UND 500.00 1475.00

Here is my WORKING code so far
Expand|Select|Wrap|Line Numbers
  2. # Writing the file to begin with, I just hard coded it to skip to good stuff#
  3. f = open("acct.txt", 'w')
  4. f.write ("03/15/11, 1000.00\n")
  5. f.write ("03/15/11, C, Hugos, 25.00\n")
  6. f.write ("03/15/11, D, UND, 500.00")
  7. f.close()
  9. # first line #
  10. g = open("acct.txt", 'r')
  11. q = g.readline()
  12. for date in q:
  13.     D = q.replace(","," ")
  14.     D = q.replace("\n","") 
  17.     print D[0:d]
  18. g.close()
any ideas to continue this would be extremely helpful, I am a newby to this, and simpler the better would be awesome!

Thanks guys
Mar 30 '11 #1
Share this Question
Share on Google+
1 Reply

P: 332
You can improve this. Look at Fancier Output Formatting
Apr 1 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.