[Tutor] .txt file out put

Daniel Yoo dyoo@CSUA.Berkeley.EDU
Fri, 13 Sep 2002 10:19:05 -0700 (PDT)


On Fri, 13 Sep 2002, Morne wrote:

> Can you help me I need the code to print out the info in any .txt file
> im using python 2.2 with the IDLE (GUI)
>
>
>
> import string
> def getStuff(file):
>  info = open(file,'r')
>  infolines = info.readlines()
>
>  avg = wordcount/len(infolines)
>         print"Average words per line %f" %(avg)
>
> file = raw_input("Enter filename:")
> getStuff(file)

There are some small indentation problems in this code.  If you're using
IDLE, you can take advantage of the 'Tab' button: it should jump 4 spaces
forward, so that you don't have to manually press the space bar all the
time.


Your reindented code may look something like this:

###
import string

def getStuff(file):
    info = open(file,'r')
    infolines = info.readlines()
    avg = wordcount/len(infolines)
    print "Average words per line %f" %(avg)

file = raw_input("Enter filename:")
getStuff(file)
###


Can you explain to us what this code does right now, and what kind of
additional information you'd like to print out.