Guest User

Untitled

a guest
Jan 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. with open('temp.txt', 'r') as inpf2:
  2. while True:
  3. c = [inpf2.read(1)]
  4. if not c:
  5. break
  6. k = c.peek(2)
  7. for d in k:
  8. if(d == ""):
  9. break
  10. else:
  11. c = c.append(d)
  12. print c
  13.  
  14. k = c.peek(2)
  15. AttributeError: 'list' object has no attribute 'peek'.
  16.  
  17. k = inpf2.peek(2)
  18.  
  19. from collections import deque
  20.  
  21. with open('temp.txt') as infile:
  22. window = deque(infile.read(2), maxlen=3)
  23. nextchar = infile.read(1)
  24. while nextchar:
  25. window.append(nextchar)
  26. print "".join(window)
  27. nextchar = infile.read(1)
Add Comment
Please, Sign In to add comment