python snippet du jour
Ben Finney
ben+bazaar at benfinney.id.au
Wed Dec 16 08:27:51 GMT 2009
Martin Pool <mbp at canonical.com> writes:
> I hope this amuses you as much as it did me:
>
> """Return the .bzrdir style format present in a directory."""
> try:
> format_string = transport.get_bytes(".bzr/branch-format")
> - except errors.NoSuchFile:
> + except errors.NoSuchFile, errors.TransportNotPossible:
> raise errors.NotBranchError(path=transport.base)
>
> try:
Whoops. That's not how to catch multiple exception types
<URL:http://docs.python.org/tutorial/errors.html#handling-exceptions>,
but it's a common mistake, and for that reason it iss invalid in Python
3 <URL:http://docs.python.org/3.1/reference/compound_stmts.html#except>.
Try this instead:
- except errors.NoSuchFile:
+ except (errors.NoSuchFile, errors.TransportNotPossible):
--
\ “We must respect the other fellow's religion, but only in the |
`\ sense and to the extent that we respect his theory that his |
_o__) wife is beautiful and his children smart.” —Henry L. Mencken |
Ben Finney
More information about the bazaar
mailing list