Format that Crap to an Array


/ Published in: Python
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.