-1

I have this code:

import itertools
res = itertools.permutations('abcdefghijklmnopqrstuvwxyz',5) # 5 is the length of the result. 
for i in res: 
   print ''.join(i)

I need the result in stead of being printed print ''.join(i) to be saved in a .txt file.

I am not familiar with python. Thank you for your time!

2
  • This is very basic; a quick google already points to a tutorial: docs.python.org/2/tutorial/inputoutput.html Commented Sep 30, 2015 at 18:55
  • All you need is to open a file object and replace print with fileobj.write(''.join(i) + '\n'). Commented Sep 30, 2015 at 18:56

1 Answer 1

1

You can open the file in write mode and just use fileobject.write method to write your permutations to the file :

with open('file_name.txt','w') as f:
    res = itertools.permutations('abcdefghijklmnopqrstuvwxyz',5) # 5 is the length of the result. 
    for i in res: 
       f.write(''.join(i)+'\n') 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.