本文整理汇总了Python中inc.Commons.Commons.check_numbers方法的典型用法代码示例。如果您正苦于以下问题:Python Commons.check_numbers方法的具体用法?Python Commons.check_numbers怎么用?Python Commons.check_numbers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inc.Commons.Commons
的用法示例。
在下文中一共展示了Commons.check_numbers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_numbers
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import check_numbers [as 别名]
def test_check_numbers(self):
valid = ["23", "2.123", " 97", "9 7"]
invalid = ["127.0.0.1", "cos(12.2)", "tan(sin(atan(cosh(1))))", "pie", "1+2*3/4^5%6", "gamma(17)", "hello",
"1&2", "$13.50", "1::", "cos(tan(12+t+15))"]
for valid_str in valid:
assert Commons.check_numbers(valid_str), "Valid string judged to be not calculation, "+valid_str
for invalid_str in invalid:
assert not Commons.check_numbers(invalid_str), "Invalid string judged to be calculation, "+invalid_str
示例2: passive_run
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import check_numbers [as 别名]
def passive_run(self, event, full_line, hallo_obj, server_obj=None, user_obj=None, channel_obj=None):
"""Replies to an event not directly addressed to the bot."""
# Check if fullLine is a calculation, and is not just numbers, and contains numbers.
if not Commons.check_calculation(full_line):
return None
if Commons.check_numbers(full_line.replace(".", "")):
return None
if not any([char in full_line for char in [str(x) for x in range(10)] + ["e", "pi"]]):
return None
# Clean up the line and feed to the calculator.
calc = full_line.replace(' ', '').lower()
try:
self.preflight_checks(calc)
answer = self.process_calculation(calc)
return answer
except Exception as e:
print("Passive calc failed: "+str(e))
return None
示例3: run
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import check_numbers [as 别名]
def run(self, line, user_obj, destination_obj=None):
if line.count(' ') == 0:
number = line
lang = "american"
elif line.split()[1].lower() in ["british", "english"]:
number = line.split()[0]
lang = "english"
elif line.split()[1].lower() in ["european", "french"]:
number = line.split()[0]
lang = "european"
else:
number = line.split()[0]
lang = "american"
if Commons.check_numbers(number):
number = number
elif Commons.check_calculation(number):
function_dispatcher = user_obj.server.hallo.function_dispatcher
calc_func = function_dispatcher.get_function_by_name("calc")
calc_obj = function_dispatcher.get_function_object(calc_func) # type: Calculate
number = calc_obj.process_calculation(number)
else:
return "Error, you must enter a valid number or calculation."
return self.number_word(number, lang) + "."