Find the number of characters in a file using Python

后端 未结 16 1450
春和景丽
春和景丽 2021-02-07 00:34

Here is the question:

I have a file with these words:

hey how are you
I am fine and you
Yes I am fine

And it is asked to find the numbe

16条回答
  •  温柔的废话
    2021-02-07 01:09

    Here is the code:

    fp = open(fname, 'r+').read()
    chars = fp.decode('utf8')
    print len(chars)
    

    Check the output. I just tested it.

提交回复
热议问题