Adam Johnson Adam Johnson - 1 year ago 46
Python Question

Writing lists to a text file in string format

This may be a simple question however, I'm currently doing an assessment and I'm on the final section.

What I need to do is write a list to a text file, but in string format. What I mean by this is for example if I want the list

['the', 'cat', 'sat', 'on', 'the', 'mat']
if I want to write this list to a text file it writes it in this format, when I need it to be written in continuous prose so
the cat sat on the mat
. I'm not sure how to do this? I tried adding
before the
command but this doesn't solve my problem.

Answer Source

Try this: F.writeline(" ".join(your_list))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download