Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. thekindlyone@deepthought:~$ cat<file.txt
  2. From: malcom@serenity.com
  3. zdfdsfsfsf
  4.  
  5. From: anara@serenity.com
  6. dfdf
  7. thekindlyone@deepthought:~$ ipython
  8. Python 2.7.6 (default, Mar 22 2014, 22:59:56)
  9. Type "copyright", "credits" or "license" for more information.
  10.  
  11. IPython 1.2.1 -- An enhanced Interactive Python.
  12. ? -> Introduction and overview of IPython's features.
  13. %quickref -> Quick reference.
  14. help -> Python's own help system.
  15. object? -> Details about 'object', use 'object??' for extra details.
  16.  
  17. In [1]: %paste
  18. fname='file.txt'
  19. try:
  20. with open(fname) as f:
  21. for line in f:
  22. words=line.split()
  23. if len(words)>1 and words[0]=='From:':
  24. print words[1]
  25. except:
  26. print 'Error opening file'
  27.  
  28. ## -- End pasted text --
  29. malcom@serenity.com
  30. anara@serenity.com
  31.  
  32. In [2]:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement