def testVariantExtract(self): """Use vtkVariantExtract""" l = [1, '2', cedilla, 4.0, vtk.vtkObject()] s = [vtk.vtkVariant(x) for x in l] m = [vtk.vtkVariantExtract(x) for x in s] self.assertEqual(l, m)
print("Index is %i" % d[vtk.vtkVariant(1.0)]) # # Extra functionality from vtk.util.vtkVariant # # These are templated functions in C++, but in Python # they take the template arg as a string instead, # e.g. vtkVariantCreate<unsigned int>(1) becomes # vtkVariantCreate(1, 'unsigned int') # Creation v = vtk.vtkVariantCreate(1, 'unsigned int') # Value extraction v = vtk.vtkVariant(6.0) f = vtk.vtkVariantExtract(v) # Value extraction with type specified f = vtk.vtkVariantExtract(v, 'double') # Casting a variant v = vtk.vtkVariant("10") i = vtk.vtkVariantCast(v, 'int') print("Valid cast result: %r" % i) # A failed cast returns None v = vtk.vtkVariant("hello") i = vtk.vtkVariantCast(v, 'int') print("Invalid cast result: %r" % i) #