開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
初めてのコンピュータサイエンス(Jennifer Campbell、Paul Gries、Jason Montojo、Greg Wilson(著)長尾 高弘(翻訳))の8章(ファイル処理)、8.8(練習問題)、1.を解いてみる。
8.8(練習問題)、1.
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 #-*- coding: utf-8 def last2first(filename): with open(filename) as f: s = f.read() for i in range(len(s) - 1, -1, -1): print(s[i], end='') last2first('sample.py') print()
入出力結果(Terminal)
$ ./sample.py )(tnirp )'yp.elpmas'(tsrif2tsal )''=dne ,]i[s(tnirp :)1- ,1- ,1 - )s(nel(egnar ni i rof )(daer.f = s :f sa )emanelif(nepo htiw :)emanelif(tsrif2tsal fed 8-ftu :gnidoc -*-# 3.3nohtyp vne/nib/rsu/!# $
0 コメント:
コメントを投稿