[Tutor] text module

Kyle Babich kyle@sent.com
Fri, 30 Aug 2002 17:27:24 UT


On Fri, 30 Aug 2002 19:18:22 +0200 (MEST), lumbricus@gmx.net said:
> Hi!
>=20
> > (called it the text module, any better
> > ideas?)=20
>=20
> Yes - wc.py, because it does just, what the *NIX wc(1) (word count)
> command does :-)
>=20
> > that will do all of this.  Before I got to far into this I
> > thought I would ask people opinions on this idea and what I have so
> > far.
> >=20
> > First of all I would appeciate it if you could test what I have so fa=
r.
> >  Here is the source (text.py):
>=20
> [ snip ]
> =20
> > def LineCount(location):
> >     subj =3D file(location, "r")
> >     body =3D subj.readlines()
> >     subj.close()
> >=20
> >     lines =3D 0
> >     for each in body:
> >         lines =3D lines + 1
> >     print lines
>=20
> Why not
> def LineCount(location):
> 	subj=3Dfile(location, "r")
> 	body=3Dsubj.readlines()
> 	subj.close()
> 	return len(body)

Because I always make more work for myself than I need too.  :)
I just changed it to the len(body) way.  I also fully commented it and
changed all of the prints to returns.
I think I will rename it to wc or something similar soon also.

>=20
> [ snip ]
>=20
> HTH, HAND
> J"o!
>=20
> --=20
>=20
> --=20
> Wir beschliessen etwas, stellen das dann in
> den Raum und warten dann einige Zeit ab, was
> passiert. Wenn es dann kein grosses Geschrei
> gibt und keine Aufstaende, weil die meisten
> gar nicht begreifen, was da beschlossen
> wurde, dann machen wir weiter - Schritt fuer
> Schritt, bis es kein Zurueck mehr gibt.=20
>    -- J-C Juncker
>=20
> GMX - Die Kommunikationsplattform im Internet.
> http://www.gmx.net
>=20
>=20
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>=20

--
Kyle