MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / NumericCell

Class NumericCell

tools/python-3.11.9-amd64/Tools/demo/spreadsheet.py:316–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314 """
315
316class NumericCell(BaseCell):
317
318 def __init__(self, value, fmt="%s", alignment=RIGHT):
319 assert isinstance(value, (int, float, complex))
320 assert alignment in (LEFT, CENTER, RIGHT)
321 self.value = value
322 self.fmt = fmt
323 self.alignment = alignment
324
325 def recalc(self, ns):
326 return self.value
327
328 def format(self):
329 try:
330 text = self.fmt % self.value
331 except:
332 text = str(self.value)
333 return text, self.alignment
334
335 def xml(self):
336 method = getattr(self, '_xml_' + type(self.value).__name__)
337 return '<value align="%s" format="%s">%s</value>' % (
338 align2xml[self.alignment],
339 self.fmt,
340 method())
341
342 def _xml_int(self):
343 if -2**31 <= self.value < 2**31:
344 return '<int>%s</int>' % self.value
345 else:
346 return '<long>%s</long>' % self.value
347
348 def _xml_float(self):
349 return '<double>%r</double>' % self.value
350
351 def _xml_complex(self):
352 return '<complex>%r</complex>' % self.value
353
354class StringCell(BaseCell):
355

Callers 3

end_valueMethod · 0.85
change_cellMethod · 0.85
test_basicFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_basicFunction · 0.68