dictStr = dictStr.splitlines() try: thread += str(dictStr[0]) except IndexError: thread += 'null' continue # Setting the fileName of the document try: fileName = 'Walt Denny - ' + i['sg_rpm_number'] + ' ' + i['cached_display_name'] except TypeError: filename = 'Walt Denny - ' + i['cached_display _name'] print fileName # Get's the id(TITLE) and formats it.Then appends the thread to it currentID = str(dict[0]['id']) if currentID in excludeID: continue list3 = sg.note_thread_read(int(currentID), formatting) for key in list3: thread += "\n" note = formatted(key) if 'content' in note: thread += str(note['content']) else: pass thread += '\n**END OF THREAD**' #Calls the Word function for file generation writeDoc(dictStr, thread, fileName)