Python版で早くも挫折
ファイルの中身の文字数、ワード数、行数を表示するコマンド(他の言語の投稿求む) - しんちゃんの日記のPython版を書こうとして、早くも挫折中・・・
一応、書いた物載せますが、splitでtabも改行もスペースも中途半端にしか取ってもらえない・・・
なぜ?
import sys for arg in sys.argv[1:]: print(str(arg)) content = open(arg).read() words = content.split(' ' or '\t' or '\n') chars = "" for word in words: chars += word chars += " " lines = content.split('\n') print("chars = ",str(len(chars))," words = ",str(len(words))," lines = ",str(len(lines))) print()