Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100433
| From | Vincent Davis <vincent@vincentdavis.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Try: rather than if : |
| Date | 2015-12-14 15:38 -0700 |
| Message-ID | <mailman.17.1450133168.14916.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Try: rather than if : Vincent Davis <vincent@vincentdavis.net> - 2015-12-14 15:38 -0700
csiph-web