News for hackers. Stuff that matters.
Re:Python hasattr() Considered Harmful by masklinn on Wednesday January 13, 2016 @07:03AM (#10893708)
Don't forget the part where checking for preconditions opens you up to race conditions e.g.

    if not file_exists(filepath):
        stderr("invalid config filepath!")
    # filepath is removed by an external tool
    config = read_file(filepath) # blows up file does not exist
Re:Python hasattr() Considered Harmful by bbradley406 on Wednesday January 13, 2016 @05:29PM (#10898127)
Is there still a chance of a race condition when you use the "with" operator? It seems like this is one of the major use cases it was designed for
Re:Python hasattr() Considered Harmful by kqr on Thursday January 14, 2016 @03:17AM (#10900161)
It depends on how you use it! If you use it to acquire the resource, as in

    with open(fn, 'r'):
        ...
then generally the answer is no, since that is the same thing as the equivalent `try…finally`. If someone removes the file after it's being opened it will not be completely wiped until it's closed.