開発環境
- macOS Catalina - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 10(Reading and Writing Files)、Exercise 1の解答を求めてみる。
コード
#!/usr/bin/env python3
filename = input('ファイル名: ')
with open(filename) as in_file, open(f'{filename}.bak', 'w') as out_file:
for line in in_file:
print(line, file=out_file, end='')
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample1.py
ファイル名: sample1.py
% diff sample1.py sample1.py.bak
% cat sample1.py.bak
#!/usr/bin/env python3
filename = input('ファイル名: ')
with open(filename) as in_file, open(f'{filename}.bak', 'w') as out_file:
for line in in_file:
print(line, file=out_file, end='')
%
0 コメント:
コメントを投稿