MCPcopy Create free account
hub / github.com/LabPy/lantz / FromQuantityProcessor

Class FromQuantityProcessor

lantz/processors.py:185–202  ·  view source on GitHub ↗

Processor to convert the units the function arguments. The syntax is equal to `Processor` except that strings are interpreted as units. >>> conv = FromQuantityProcessor('ms') >>> conv(Q_(1, 's')) 1000.0

Source from the content-addressed store, hash-verified

183
184
185class FromQuantityProcessor(Processor):
186 """Processor to convert the units the function arguments.
187
188 The syntax is equal to `Processor` except that strings are interpreted
189 as units.
190
191 >>> conv = FromQuantityProcessor('ms')
192 >>> conv(Q_(1, 's'))
193 1000.0
194
195 """
196
197 @classmethod
198 def to_callable(cls, obj):
199 if isinstance(obj, (str, Q_)):
200 return convert_to(obj, return_float=True)
201 raise TypeError('FromQuantityProcessor argument must be a string '
202 ' or a callable, not {}'.format(obj))
203
204
205class ToQuantityProcessor(Processor):

Callers 2

rebuildMethod · 0.85
rebuildMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected