我有一项职能,即在必要时进行扼杀,把事情交给它,并将结果退回。
我的自然倾向是,仅仅回报结果,因为结果涉及扼杀,如果它失败,则让打电话者感到例外。 然而,这一职能具有缺省价值,我刚刚回过来。
我的问题是:如果有人对这种方法寄出一些意想不到的东西,又回到用户所期望的东西? 这种方法应当失败,但如何执行?
我有一项职能,即在必要时进行扼杀,把事情交给它,并将结果退回。
我的自然倾向是,仅仅回报结果,因为结果涉及扼杀,如果它失败,则让打电话者感到例外。 然而,这一职能具有缺省价值,我刚刚回过来。
我的问题是:如果有人对这种方法寄出一些意想不到的东西,又回到用户所期望的东西? 这种方法应当失败,但如何执行?
没有必要这样做,但如果你知道该物体属于你无法处理的类别,那么如果你想要你能够用上
标准图书馆的一些方法就是:
>>> [] + 1 Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate list (not "int") to list
You can use decorators for this kind of thing, you can see an example here.
但是,迫使参数属于某种特定类型,是 t。
粉碎的假设是,我们都是智慧的成年人,读到文件。 如果你仍然想这样做,那么你就不应该坚持实际的类型,而是在论据不支持你所需要的行动时,就只能满足例外情形。
def foo(arg):
try:
return arg + "asdf"
except TypeError:
return arg
违约价值如何? 如果打电话者没有穿透镜,你是否希望回去虚设的价值? 在这种情况下:
def yourFunc( foo ):
try:
return foo + " some stuff"
except TypeError:
return "default stuff"
1. 空间-C0wb0y如果希望恢复动力而不作扼杀,则有正确的答案,还有试图将某些东西改成扼子的选择:
def yourFunc2( bar ):
return str(bar) + " some stuff"
这些工作将多种多样。
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ]="...