Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 27th, 2013  |  syntax: None  |  size: 0.46 KB  |  views: 160  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. 192.168.0.1:8000 = 2
  2. 192.168.0.10:80 = 1
  3. 192.168.0.100:3128 = 2
  4. 192.168.0.4:8080
  5. 192.168.0.5:7822 = 2
  6. 192.168.0.6:8005
  7.        
  8. searchValue = "192.168.0.10:80"
  9. newNumber = 2
  10.  
  11. f = open("datafile.txt", "r+b")
  12.  
  13. for line in file:
  14.     if line.split()[0] == searchValue:
  15.         position = f.tell() - len(line) #the tell() method gives the current position in the file
  16.         f.seek(position)
  17.         f.write("%s = %d" % (searchValue, newNumber))
  18.         break
  19.  
  20. f.close()