Python: TypeError: coercing to Unicode: need string or buffer, module found
Question: I am new to Python, just learning.

I am taking one of the file as input and I want to print the text on the
console using python.

    
    
    # This will take the file as input
    
    import fileinput
    for line in fileinput.input():
    
        print "The file name you provided is " + fileinput.filename()
    
        #file of = open(fileinput, "r", 0)
        with open(fileinput,'r') as myfile:
            data=myfile.read()
            print "This is your actual data \n\n" + data
    

The error I'm experiencing is:

    
    
    TypeError: coercing to Unicode: need string or buffer, module found
    

Could any one please help me out on this please.


Answer: This particular problem is in the line below:

    
    
    with open(fileinput,'r') as myfile:
    

`fileinput` is a module. I presume you mean to have:

    
    
    with open(fileinput.filename(),'r') as myfile:
    

