Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100433 > unrolled thread

Try: rather than if :

Started byVincent Davis <vincent@vincentdavis.net>
First post2015-12-14 15:38 -0700
Last post2015-12-14 15:38 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Try: rather than if : Vincent Davis <vincent@vincentdavis.net> - 2015-12-14 15:38 -0700

#100433 — Try: rather than if :

FromVincent Davis <vincent@vincentdavis.net>
Date2015-12-14 15:38 -0700
SubjectTry: rather than if :
Message-ID<mailman.17.1450133168.14916.python-list@python.org>
In the code below try is used to check if handle has the attribute name. It
seems an if statement could be used. Is there reason one way would be
better than another?

def write_header(self):
    handle = self.handle
    try:
        handle.write("# Report_file: %s\n" % handle.name)
    except AttributeError:
        pass
    handle.write("########################################\n")

The specific use case I noticed this was
https://github.com/biopython/biopython/blob/master/Bio/AlignIO/EmbossIO.py#L38

Vincent Davis

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web