How does using the try statement avoid a race condition?
问题 When determining whether or not a file exists, how does using the try statement avoid a "race condition"? I'm asking because a highly upvoted answer (update: it was deleted) seems to imply that using os.path.exists() creates an opportunity that would not exist otherwise. The example given is: try: with open(filename): pass except IOError: print 'Oh dear.' But I'm not understanding how that avoids a race condition compared to: if not os.path.exists(filename): print 'Oh dear.' How does calling