小编xpo*_*ter的帖子

有没有一种很好的方法来处理Python中的异常?

我有一堆类似于此的代码:

                try:
                    auth = page.ItemAttributes.Author
                except:
                        try:
                            auth = page.ItemAttributes.Creator
                        except:
                                auth = None
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来写出这个逻辑?这使我的代码真的很难阅读.我认为尝试..最终会起作用,但我认为错了

python exception

6
推荐指数
1
解决办法
266
查看次数

标签 统计

exception ×1

python ×1