This piece of code when run on Python 2.7.16 and 3.8.3 produces different results: import tempfile import os fd, lockfile = tempfile.mkstemp() flags = os.O_RDWR | os.O_CREAT mode = 'w+b' fd = os.open(lockfile, flags) fileobj = os.fdopen(fd, mode) print(fileobj.mode) os.remove(lockfile) In 2.7 it prints w+b as expected but in 3.8 it prints rb+. Why wouldn't it be respecting the mode parameter in this way? I've tried manually creating a file to discount tempfile differences but still get the same result. I can't see anything obvious in the docs: https://docs.python.org/3.8/library/os.html#os.fdopen https://docs.python.org/2.7/library/os.html#os.fdopen Running on MacOS 10.14.6 Continue reading...