Hi there,

I got this here:

file_path = "C:\\Users\\...\\MyFile.txt" # path shortened for better readability
with open(file_path) as file_object:
    contents = file_object.read()
    print(contents)

It works.

Now I want to convert the code above into a function.
This is what I wrote:

def FileReader(file_path):
    with open(file_path) as file_object:
        contents = file_object.read
        return contents

print(FilePrinter("C:\\Users\\...\\MyFile.txt")) # path shortened for
better readability

I got this error message:

<built-in method read of _io.TextIOWrapper object at 0x000001CA44448558>

How do I fix my function?

Thanks,

Rafael
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to