ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 22 Mar 2013 07:02:18 +0100How to get a Boolean from the type of an object?https://ask.sagemath.org/question/9933/how-to-get-a-boolean-from-the-type-of-an-object/I am trying to define the `__init__` of a class, where I would like to support different types of input; in my case the input could be a either a list of pairs or a matrix. How do I write a Boolean function to test which kind of input I have? In the example code, I want to know how I should define the Boolean functions `is_a_matrix(A)` and `is_a_tuple_of_pairs(A)` (and of course more generally testing `A` to be of some other type)
class someclass():
def __init__(self, A):
if is_a_matrix(A):
self._matrix = A
if is_a_tuple_of_pairs(A):
self._matrix = somefunction(A)AmriFri, 22 Mar 2013 07:02:18 +0100https://ask.sagemath.org/question/9933/