python中命名不唯一结果错误?

发布于 2024-11-14 21:29:06 字数 941 浏览 0 评论 0原文

也许这是一个有点非常规的问题,但我想听到一个答案。由于英语不是我的母语,我想我应该征求第二意见。

我想在 python 中提出一个错误,并且想知道如何命名它。

class AmbiguousResultError(Exception): pass
class NoResultFoundError(Exception): pass

def getUrlFor(mystring):
    list_of_urls = []
    # parse url object for all matching urls for the given string
    # and add them to list_of_urls
    if len(url) > 1:
        raise AmbiguousResultError("More then one url matches for {0}".format(mystring))
    elif not url:
        raise NoResultFoundError("There was no matching url for {0}".format(mystring))
    else:
        return list_of_urls[0]

第一个 raise 是我想知道的,如何命名它才能准确。我想到了

  1. NoUniqueResultFoundError
  2. AmbigouslyResultError
  3. UncertainResultError

但它们都不能让我满意,我也不知道这个命名是否切中要害。对于其他人来说也应该是显而易见的。必须有一个具体的表达方式。是哪一个呢。我想在 english.stackexchange.com 上提问,但我认为程序员的思维方式与语言学家不同。

Maybe this is a little unconventional question but I'd like to hear an answer to it. Since english is not my native language I thought I'd ask for a second opinion.

I want to raise an Error in python and was wondering how to name it.

class AmbiguousResultError(Exception): pass
class NoResultFoundError(Exception): pass

def getUrlFor(mystring):
    list_of_urls = []
    # parse url object for all matching urls for the given string
    # and add them to list_of_urls
    if len(url) > 1:
        raise AmbiguousResultError("More then one url matches for {0}".format(mystring))
    elif not url:
        raise NoResultFoundError("There was no matching url for {0}".format(mystring))
    else:
        return list_of_urls[0]

The first raise is the one which I was wondering, how to name it such that it is precise. I thought of

  1. NoUniqueResultFoundError
  2. AmbiguousResultError
  3. UncertainResultError

But they all don't satisfy me, and I don't know if I hit the nail with this nameing. It should be obvious to others, too. There has to be a specific expression for that. Which one is it. I thought of asking it on english.stackexchange.com, but I think a programmer has another sort of thinking then a philologist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亚希 2024-11-21 21:29:06

我更喜欢 AmbigouslyStringError 而不是 AmbigouslyResultError。毕竟,具有多重含义的不是结果,而是用户提供的字符串。

或者可能是MultipleResultsFoundError。我认为你的 NoUniqueResultFoundError 建议是一样好的。如果您像对待此代码一样对其余代码进行彻底和深思熟虑,那么其他开发人员在调试它时就不会有问题。

I'd prefer AmbiguousStringError to AmbiguousResultError. After all, it's not the result that has multiple meanings, it's the string the user provided.

Or possibly MultipleResultsFoundError. I think your suggestion of NoUniqueResultFoundError is as good as anything though. If you're as thorough and thoughtful with the rest of your code as you are with this, other developers won't have a problem debugging it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文