Home 9 The Art of Technology 9 Python Automation – Code Snippet – Return Text File Contents

This function will read and text file and return text file contents.

#usage yourContentHolder = return_text_file_content(path to text file)
def return_text_file_content(file):
    encoding_format = "utf-8"
    textDataFile = open(file, mode="r",encoding= encoding_format)
    textContent = textDataFile.read()
    textDataFile.close()
    return textContent

Usage – yourcontentholder = return_text_file_content(path and file name to text file)


Need a Creator Alchemist on Your Project?

I’m available for hire—consulting, systems design, embedded tech, creative problem-solving, or anything in between.

If you’ve got a project that needs someone who can think it through and build it out, I’m interested.


LET’S KEEP IN TOUCH!

Get notified when I post something new!

We don’t spam! Read our privacy policy for more info.


Pin It on Pinterest

Share This