Write entire file: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Add method using Pathlib)
m (→‎{{header|Python}}: Remove extra spacing)
Line 605: Line 605:


=={{header|Python}}==
=={{header|Python}}==
<lang python>
<lang python>with open(filename, 'w') as f:
f.write(data)</lang>
with open(filename, 'w') as f:
f.write(data)
</lang>


Starting in Python 3.4, we can use <code>pathlib</code> to reduce boilerplate:
Starting in Python 3.4, we can use <code>pathlib</code> to reduce boilerplate:


<lang python>
<lang python>from pathlib import Path
from pathlib import Path


Path(filename).write_text(any_string)
Path(filename).write_text(any_string)
Path(filename).write_bytes(any_binary_data)
Path(filename).write_bytes(any_binary_data)</lang>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==