我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用marshmallow.fields.Number()。
def inline(self, field, context): # type: (fields.Field, JitContext) -> Optional[str] """Generates a template for inlining string serialization. For example, generates "float(value) if value is not None else None" to serialize a float. If `field.as_string` is `True` the result will be coerced to a string if not None. """ if (is_overridden(field._validated, fields.Number._validated) or is_overridden(field._serialize, fields.Number._serialize)): return None result = field.num_type.__name__ + '({0})' if field.as_string and context.is_serializing: result = 'str({0})'.format(result) if field.allow_none is True: # Only emit the Null checking code if nulls are allowed. If they # aren't allowed casting `None` to an integer will throw and the # slow path will take over. result += ' if {0} is not None else None' return result
def field_to_dynamo_type(field): """Given a marshmallow field object return the appropriate Dynamo type character""" if isinstance(field, fields.Raw): return 'B' if isinstance(field, fields.Number): return 'N' return 'S'