我们有时候需要统计一个文件里边有多少个字符怎么办呢???接下来我们实现一下。
try: with open('E:/python/day5/filePath/readerFile.txt') as file_object: contents = file_object.read() except FileNotFoundError: print("没找到文件") else: words = contents.split() number = len(words) print("the file : have " + str(number) + " words !")