Posted By

magicrebirth on 09/22/10


Tagged

file write append


Versions (?)

File overwrite and append in python


 / Published in: Python
 

URL: http://www.wellho.net/resources/ex.php4?item=y110/tablog.py

  1. #!/usr/local/bin/python
  2.  
  3. import sys
  4. import time
  5.  
  6. havevalue = 0
  7.  
  8. while havevalue < 1:
  9.         try:
  10.                 table = input("What table to you want? ")
  11.                 havevalue=1
  12.         except:
  13.                 print "Looking for a number"
  14.  
  15. counter = 1
  16.  
  17. save = open("tabout.txt","w")
  18. while counter <12:
  19.         result = table * counter
  20.         print counter,"time",table, "is",result
  21.         save.write (str(counter) " times "  \
  22.                 str(table)  " is "  \
  23.                 str(result)   "\n")
  24.         counter = counter   1
  25.  
  26. print "Counter ends at",counter
  27. save.close();
  28.  
  29. handle = open("logfile.txt","a")
  30. logline = []
  31. logline.append(sys.argv[0])
  32. logline.append(str(time.time()))
  33. logline.append(str(table))
  34. handle.write((" ".join(logline)) "\n")
  35. handle.close()

Report this snippet  

You need to login to post a comment.