[Tutor] text module

Kyle Babich kyle@sent.com
Sat, 31 Aug 2002 00:39:50 UT


On Fri, 30 Aug 2002 22:30:42 +0200, "Francois Granger"
<fgranger@altern.org> said:
> At 16:50 +0000 30/08/02, in message [Tutor] text module, Kyle Babich
> wrote:
> >   Before I got to far into this I
> >thought I would ask people opinions on this idea and what I have so
> >far.
>=20
> Nice
>=20
> >####################
> >import string
>=20
> import string, sys # needed for command line arguments later
>=20
> >def CharCount(location, spaces):
>=20
> def CharCount(location, spaces =3D 1): # give it a default value....
>=20
> >def LineCount(location):
> >     subj =3D file(location, "r")
> >     body =3D subj.readlines()
> >     subj.close()
> >
> >     lines =3D 0
> >     for each in body:
> >         lines =3D lines + 1
> >     print lines
>=20
>=20
> def main():
>      for file in sys.argv[1:]:
>          print 'File : ', file
>          print 'Char count : ', CharCount(file)
>          print 'Word count : ', WordCount(file)
>          print 'Line count : ', LineCount(file)
>=20
> if __name__ =3D=3D '__main__':
>      """Allow for command line argument.
>      handling the argument for space handling is not included.
>      """
>      main()

I added something similar:
def main():
    for file in sys.argv[1:]:
        print "File: ", file
        print "Word Count: ", WordCount(file)
        print "Character Count: ", CharCount(file)
        print "Line Count: ", LineCount(file), "\n"

if __name__ =3D=3D "__main__":
    main()

But the output is this:
C:\Python22>c:\python22\python c:\python22\wc.py
c:\windows\desktop\temp.txt
File: c:\windows\desktop\temp.txt
Word Count: 7
Character Count: 29
None
Line Count: 5

Where is the None coming from though?

>=20
> HTH
>=20
> file enclosed...