0

i recently started python and i wanna learn how to implement modules in my program, but when ever i try to string modules together it says function not callable how do u make functions callable and if u cant then how would u put this code

'readTextfile.py--reads and displays text files'

def opener():
    #get filename:'

    fname = raw_input('enter filename: ')
    print

    #attempt to open a file for reading
    try:
        fobj =open(fname, 'r')
    except IOError, e:
        print"**** file open errpr:", e
    else:
        # display contents on screen
        for eachline in fobj:
            print eachline,
        fobj.close()

along with 3 other ones in a program via importing modules.

Edited by mike_2000_17: Fixed formatting

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by woooee
0

sorry mixed up on the tags

'readTextfile.py--reads and displays text files'

def opener():
    #get filename:'

    fname = raw_input('enter filename: ')
    print

    #attempt to open a file for reading
    try:
        fobj =open(fname, 'r')
    except IOError, e:
        print"**** file open errpr:", e
    else:
        # display contents on screen
        for eachline in fobj:
            print eachline,
        fobj.close()
0

If you want to run this program file by itself, put the following at the bottom. You can then run the program from the command line with "python program_name". Take a look at the "Starting Python" thread at the top of this forum.

if __name__ == "__main__":
   opener
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.