Redirecting the print output to a .txt file in Python
Question: I am complete beginner in Python. I have tried many methods from stackoverflow
answers on this question, but neither of them works in my script.  
I have this little script to use, however I can not get the huge result to
.txt file so I can analyize the data. How do I redirect the print output to
txt file on my computer?

    
    
    from nltk.util import ngrams
    import collections
    
    with open("text.txt", "rU") as f:
        sixgrams = ngrams(f.read().decode('utf8').split(), 2)
    
    result = collections.Counter(sixgrams)
    print result
    for item, count in sorted(result.iteritems()):
        if count >= 2:
            print " ".join(item).encode('utf8'), count
    


Answer: Just do it on command line: `python script.py > text.txt`

