本文整理汇总了Python中error.Error类的典型用法代码示例。如果您正苦于以下问题:Python Error类的具体用法?Python Error怎么用?Python Error使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Error类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: suitable_pile_pop
def suitable_pile_pop(self, bottomCard):
"""
each Card in the pile
is face-up, the pile alternates in color, and the pile is
built top down. Additionally, all Cards in the given pile must
be face-up.
"""
if bottomCard is None:
Error.print_error(Error.CARD_IS_NONE, lineno())
return False
if bottomCard.is_face_down():
Error.print_error(Error.CARD_IS_FACE_DOWN, lineno())
return False
idx = self.index(bottomCard)
popped = self[idx:]
evenColor = bottomCard.color()
for i in range(len(popped)):
c = popped[i]
if c.is_face_down():
Error.print_error(Error.CARD_IS_FACE_DOWN, lineno())
if c.rank != bottomCard.rank - i:
Error.print_error(Error.INVALID_RANK, lineno())
if i % 2 == 0 and c.color() != evenColor or i % 2 == 1 and c.color() == evenColor:
Error.print_error(Error.INVALID_COLOR, lineno())
if (
c.is_face_down()
or c.rank != bottomCard.rank - i
or i % 2 == 0
and c.color() != evenColor
or i % 2 == 1
and c.color() == evenColor
):
return False
return True
示例2: suitable_card_pop
def suitable_card_pop(self):
"""
@todo: commentme
"""
if self.is_empty():
Error.print_error(Error.EMPTY_PILE, lineno())
return not self.is_empty()
示例3: test_gradient
def test_gradient(self, xL, xR, cat):
epsilon = 10**(-8)
a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb = self.forward_pass(xL, xR)
grad3, grad2L, grad2LR, grad2R, grad1L, grad1R = self.backward_pass(a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb, cat)
expected_gradient = grad1L[0,8];
e=Error()
self.w1l[0,8] += epsilon
a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb = self.forward_pass(xL, xR)
e_plus = e.total_error(a3,cat, self.k)[0]
self.w1l[0,8] -= (2*epsilon)
a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb = self.forward_pass(xL, xR)
e_minus = e.total_error(a3,cat, self.k)[0]
self.w1l[0,8] += epsilon
difference = (e_plus-e_minus)
approx_grad = difference/(2*epsilon)
print "Derivative = "+str(approx_grad)
print "Gradient = "+str(expected_gradient)
print "Difference "+str(approx_grad-expected_gradient)
示例4: testLogisticError
def testLogisticError():
k = 5
data = Data(k, 0, 0)
data.importDataFromMat()
data.normalize()
lg = LogisticLinearClassifier(0.03, 0.03, 576, k, data)
err_train, miss_train, err_val, miss_val = lg.train(30)
mis_fig = plt.figure()
ax2 = mis_fig.add_subplot(111)
ax2.plot(err_val, label="error (validation)")
ax2.plot(err_train, label="error (training)")
title = "std(val)=%f std(err)=%f" % (sp.std(err_val), sp.std(err_train))
mis_fig.suptitle(title)
ax2.set_ylabel("error")
ax2.set_xlabel("epoch")
plt.legend()
mis_fig = plt.figure()
ax2 = mis_fig.add_subplot(111)
ax2.plot(miss_val, label="misclassification ratio (validation)")
ax2.plot(miss_train, label="misclassification ratio (training)")
mis_fig.suptitle(title)
ax2.set_ylabel("misclassification ratio")
ax2.set_xlabel("epoch")
plt.legend()
results, cat = lg.classify(data.test_left, data.test_right)
lg.confusion_matrix(cat, data.test_cat.argmax(axis=0))
err = Error()
err, misclass = err.norm_total_error(results.T, data.test_cat, k)
print "Error on the test set " + str(err)
print "Misclassification ratio on the test set " + str(misclass)
示例5: sort_into_dictionary
def sort_into_dictionary(wedding_list, guest_list):
'''sort_into_dictionary(str, dictionary_object)
Takes a grouping of strings and sorts them into
a python dictionary object. A python dictionary object is implemented
using a hash function. This makes anything involving look up extremly
fast. Much faster then using a list object.
'''
error = Error()
wedding_list = wedding_list.split(",")
for guest in wedding_list:
# ensure that the name before the dash is not empty
try:
name = guest.split("-")[0].strip().title()
response = guest.split("-")[1].strip("\n").lower()
except IndexError:
error.data_error()
else:
# check that responses in rsvp file is not empty
if not response or not name:
error.data_error()
# adds the names and replies to the dictionary object. If the name
# already exists meaning that there is another guest with same name
# append their reply to that name
if name not in guest_list.keys() :
guest_list[name] = [response]
else:
guest_list[name].append(response)
示例6: pop_card
def pop_card(self):
"""
Equivalent to deque.pop(), but is overridden by Pile subclasses
for additional functionality.
"""
if self.suitable_card_pop():
return self.pop()
Error.print_error(Error.ILLEGAL_POP_CARD, lineno())
示例7: push_card
def push_card(self, card):
"""
The same as push(), but is overridden by Pile subclasses to
check if pushing the Card to this Pile is legal.
"""
if self.suitable_card_push(card):
return self.push(card)
Error.print_error(Error.ILLEGAL_PUSH_CARD, lineno())
示例8: enqueue_card
def enqueue_card(self, card):
"""
The same as enqueue(), but overwritten by Pile subclasses. Only
legal for Stock piles.
"""
if self.suitable_card_enqueue(card):
return self.enqueue(card)
Error.print_error(Error.ILLEGAL_ENQUEUE_CARD, lineno())
示例9: verify_fetch
def verify_fetch(self, array_pos):
"""Verifies that truncation or other problems did not take place on retrieve."""
if self.type.is_variable_length:
if self.return_code[array_pos] != 0:
error = Error(self.environment, "Variable_VerifyFetch()", 0)
error.code = self.return_code[array_pos]
error.message = "column at array pos %d fetched with error: %d" % (array_pos, self.return_code[array_pos])
raise DatabaseError(error)
示例10: push_pile
def push_pile(self, pile):
"""
Pushes a list of Cards to the top of this Pile, if it is legal
to do so. Overridden by subclasses for which pushing a Pile is
legal.
"""
if self.suitable_pile_push(pile):
return self.extend(pile)
Error.print_error(Error.ILLEGAL_PUSH_PILE, lineno())
示例11: suitable_pile_pop
def suitable_pile_pop(self, bottomCard):
"""
@todo: commentme
"""
if bottomCard is None:
Error.print_error(Error.CARD_IS_NONE, lineno())
if not bottomCard in self:
Error.print_error(Error.CARD_NOT_IN_PILE, lineno())
return bottomCard is not None and bottomCard in self
示例12: __get_active_policies
def __get_active_policies(self, repository_name):
Error.abort_if(repository_name not in self.settings['repo_id'], "Couldn't find this repository on your TFS")
auth = self.__get_auth()
fullUrl = self.settings['url'] + '/' + self.settings['project'] + '/_apis/policy/configurations?api-version=2.0'
policies = requests.get(fullUrl, auth=auth).json()['value']
policies_from_repository = filter(lambda policy: policy["settings"]["scope"][0]["repositoryId"] == self.settings['repo_id'][repository_name], policies)
return list(policies_from_repository)
示例13: cr
def cr(ctx):
try:
if (not Configuration.exists()):
Utils.print_encoded("Please inform your TFS' information\n")
ctx.invoke(configure, url=click.prompt("Url"), username=click.prompt("Username"), password=click.prompt("Password"))
ctx.exit()
repo = git.Repo('.')
ctx.obj = Repository(repo, RepositoryUtils(repo), Tfs(Configuration.load()))
except git.exc.InvalidGitRepositoryError:
Error.abort("You're not on a valid git repository")
示例14: check_for_error
def check_for_error(self, status, context):
if status != oci.OCI_SUCCESS and status != oci.OCI_SUCCESS_WITH_INFO:
if status != oci.OCI_INVALID_HANDLE:
self.raise_error(context)
error = Error(self, context, 0)
error.code = 0
error.message = "Invalid handle!"
raise DatabaseError(error)
示例15: suitable_card_enqueue
def suitable_card_enqueue(self, card):
"""
Enqueues the specified card to this Pile if it exists and if
this Pile is not full. Overridden by subclasses.
"""
if card is None:
Error.print_error(Error.CARD_IS_NONE, lineno(), False)
if len(self) >= self.maxlen:
Error.print_error(Error.EXCEEDS_MAXIMUM, lineno(), False)
return card is not None and len(self) < self.maxlen