double space when exporting to TXT file in python

110 views Asked by At

I have this code that works:

print((tabulate(email_list, showindex=False, tablefmt = 'plain')), file=open(output + '\\' + "np.txt", "w"))

but when I open the file, the email addresses look like this:

b  e  r  o  s  u  n  a  @  g  m  a  i  l  .  c  o  m

I have tried all the tablefmts and none work, I need it as plain text with no index and no headers left aligned because then I copy them and use it in another process.

1

There are 1 answers

0
Berny On BEST ANSWER

Thanks I just changed it completely:

emails = email_list.tolist()
textfile = open(output + '\\' + "np.txt", "w")
for element in emails:
    textfile.write(element + "\n")
textfile.close()
os.startfile(output + '\\' + 'np.txt')