DEV Community

Discussion on: Dead Simple Python: Working with Files

Collapse
 
rpural profile image
Robert Nix

In your examples of writelines(), you pass a list containing a single string element, but in practice, isn’t the usefulness of writelines() in passing several individual lines in a list?

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Hmm, I appear to be doing exactly that? I'm not sure what you mean.

lines = [
    "Finally back safe and sound\n",
    "from one of the weirdest days\n",
    "at Gravity Falls.\n"
]
with open("journal3.txt", 'w') as file:
    file.writelines(lines)