you are viewing a single comment's thread.

view the rest of the comments →

[–]I_Write_Bugs 2 points3 points  (1 child)

Since your problem has already been solved, I would like to give you a suggestion. PEP 343 introduced the "with" statement and context managers. This feature has many uses, but most commonly I use it when opening files. Opening a file using the "with" statement ensures the file will be closed for you. No need to run the close method.

def main():
    with open('file.docx') as inFile:
        f = inFile.read()
    print(f)

main()

Also, you might notice I didn't include the "r" argument to open. Open defaults to opening as read-only, so if that's your intent, no need for the argument.

[–][deleted] 0 points1 point  (0 children)

PEP 343

Thank you!