Posted By

joshuaherman on 04/18/15


Tagged

parse number array String int


Versions (?)

Format that Crap to an Array


 / Published in: Python
 

I am tired of having to go through text and adding quotation marks and commas to strings or just commas after numbers... f-that. Fixed.

  1. f = open("filename.txt", "r+")
  2.  
  3. for line in f:
  4. newline = line.rstrip('\n')
  5.  
  6. if(newline.isalpha()):
  7. print '"'+ newline + '", '
  8. elif(newline.isalnum()):
  9. print newline + ", "
  10. else:
  11. print '"'+ newline + '", '
  12.  
  13. f.close()

Report this snippet  

You need to login to post a comment.