Count letters in a text file

后端 未结 8 1100
無奈伤痛
無奈伤痛 2020-12-06 21:13

I am a beginner python programmer and I am trying to make a program which counts the numbers of letters in a text file. Here is what I\'ve got so far:

import         


        
8条回答
  •  天命终不由人
    2020-12-06 21:56

    import sys
    
    def main():
        try:
             fileCountAllLetters = file(sys.argv[1], 'r')
             print "Count all your letters: ", len(fileCountAllLetters.read())
        except IndexError:
             print "You forget add file in argument!"
        except IOError:
             print "File like this not your folder!"
    
    main()
    

    python file.py countlettersfile.txt

提交回复
热议问题