Make a backup file: Difference between revisions
→{{header|Python}}: Added a version using pathlib
SqrtNegInf (talk | contribs) (Added Perl example) |
(→{{header|Python}}: Added a version using pathlib) |
||
Line 477:
=={{header|Python}}==
Using [https://docs.python.org/library/os.html os library]
<lang Python>
import os
Line 484 ⟶ 485:
f.write("this task was solved during a talk about rosettacode at the PyCon China in 2011")
f.close()
</lang>
Or using a newer [https://docs.python.org/library/pathlib.html pathlib library] (Python >= 3.4):
<lang Python>
from pathlib import Path
filepath = Path("original_file")
filepath.rename(filepath.with_suffix('.bak'))
with filepath.open('w') as file:
file.write("New content")
</lang>
|