English 中文(简体)
我将接口通用的例外定义放在哪里?
原标题:Where do I put exception definitions common to an interface?

我开始习惯在设计某些课程时使用zope. interface, 这很好,很好,但我不太确定例外。 我从未见过任何医生谈论过这些例外(尽管只是在草图搜索之后 ) 。 最重要的是,我想知道在什么情况下可以设置某种例外 X, 这在任何接口的实施中都是常见的。

我总是可以将例外设置在自己的模块中。但是,对于什么可以是一个简单的例外来说,一个完整的模块?我不介意把它放在定义相关界面的同一个模块中,但我想知道,这在某种意义上是被视为坏形式呢?

基本上,我愿意听到有人 曾经使用过界面 并且知道为此的公约。

最佳回答

最佳做法是有一个 interface 模块,其中包括所有有文件记录的接口和相应的例外、常数和活动。

这样,您就可以在一个定义明确的地方定义您的软件包的 API, 某个人向上查看接口, 可以看到任何被丢弃的例外都在同一地点定义 。

以下是一些来自多个工程的示例界面. py 文件 :

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签