import sys
import mailbox
import mail_parser
import nltk
import itertools
try:
    import cPickle as pickle
except ImportError:
    import pickle

def main():
    """Extract the texts of emails from a specified mailbox and
    from a specified set of senders and write corpus.txt.

    Usage: python mail_corpus.py output mboxfile email1@example.com email2@example.com
    """
    mbox = mailbox.mbox(sys.argv[2])
    addresses = set(sys.argv[3:])
    f = open(sys.argv[1], "w")
    for text in mail_parser.mail_texts(mbox, addresses):
        print >> f, text
    f.close()

if __name__ == '__main__':
    main()

import sys
import mailbox
import mail_parser
import nltk
import itertools
try:
    import cPickle as pickle
except ImportError:
    import pickle

def main():
    """Extract the texts of emails from a specified mailbox and
    from a specified set of senders and write corpus.txt.

    Usage: python mail_corpus.py mboxfile email1@example.com email2@example.com
    """
    mbox = mailbox.mbox(sys.argv[1])
    addresses = set(sys.argv[2:])
    f = open("corpus.txt", "w")
    for text in mail_parser.mail_texts(mbox, addresses):
        print >> f, text
    f.close()

if __name__ == '__main__':
    main()

Switch back to always write corpus.txt
Switch back to always write corpus.txt

  import sys
  import mailbox
  import mail_parser
  import nltk
  import itertools
  try:
      import cPickle as pickle
  except ImportError:
      import pickle
  
  def main():
      """Extract the texts of emails from a specified mailbox and
      from a specified set of senders and write corpus.txt.
  
-     Usage: python mail_corpus.py output mboxfile email1@example.com email2@example.com
+     Usage: python mail_corpus.py mboxfile email1@example.com email2@example.com
      """
-     mbox = mailbox.mbox(sys.argv[2])
+     mbox = mailbox.mbox(sys.argv[1])
-     addresses = set(sys.argv[3:])
+     addresses = set(sys.argv[2:])
-     f = open(sys.argv[1], "w")
+     f = open("corpus.txt", "w")
      for text in mail_parser.mail_texts(mbox, addresses):
          print >> f, text
      f.close()
  
  if __name__ == '__main__':
      main()
  
Switch back to always write corpus.txt
## Code Before:
import sys
import mailbox
import mail_parser
import nltk
import itertools
try:
    import cPickle as pickle
except ImportError:
    import pickle

def main():
    """Extract the texts of emails from a specified mailbox and
    from a specified set of senders and write corpus.txt.

    Usage: python mail_corpus.py output mboxfile email1@example.com email2@example.com
    """
    mbox = mailbox.mbox(sys.argv[2])
    addresses = set(sys.argv[3:])
    f = open(sys.argv[1], "w")
    for text in mail_parser.mail_texts(mbox, addresses):
        print >> f, text
    f.close()

if __name__ == '__main__':
    main()

## Instruction:
Switch back to always write corpus.txt
## Code After:
import sys
import mailbox
import mail_parser
import nltk
import itertools
try:
    import cPickle as pickle
except ImportError:
    import pickle

def main():
    """Extract the texts of emails from a specified mailbox and
    from a specified set of senders and write corpus.txt.

    Usage: python mail_corpus.py mboxfile email1@example.com email2@example.com
    """
    mbox = mailbox.mbox(sys.argv[1])
    addresses = set(sys.argv[2:])
    f = open("corpus.txt", "w")
    for text in mail_parser.mail_texts(mbox, addresses):
        print >> f, text
    f.close()

if __name__ == '__main__':
    main()
