我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用decimal.Overflow()。
def make_decimal( self, s, sign='+' ): """Converts a string into a decimal or float value.""" if not decimal or self.float_type == NUMBER_FLOAT: return self.make_float( s, sign ) if s.startswith('-') or s.startswith('+'): sign = s[0] s = s[1:] elif isinstance(sign, (int,long)): if sign < 0: sign = '-' else: sign = '+' try: f = self.decimal_context.create_decimal( s ) except decimal.InvalidOperation: f = self.decimal_context.create_decimal( 'NaN' ) except decimal.Overflow: if sign=='-': f = self.decimal_context.create_decimal( '-Infinity' ) else: f = self.decimal_context.create_decimal( 'Infinity' ) else: if sign=='-': f = f.copy_negate() return f