How can I write to multiple files in Python?

93 views

How can I write to multiple files in Python?

How can I write to multiple files in Python?

solveurit24@gmail.com Changed status to publish February 13, 2025
0

Open multiple file handles and write to each.

with open('file1.txt', 'w') as f1, open('file2.txt', 'w') as f2:
    f1.write("Hello file1")
    f2.write("Hello file2")

solveurit24@gmail.com Changed status to publish February 13, 2025
0
You are viewing 1 out of 1 answers, click here to view all answers.