I believe you can replace these four lines with filetxt = open(fileid, "r").read()