2

I give the following example to illustrate my question:

import numpy as np
var1 = np.random.rand(3,4)
[e for e in dir(var1) if not e.startwith("__")]

We can see var1 has the following attributes:

['T', 'all', 'any', 'argmax', 'argmin', 'argpartition', 'argsort', 'astype', 'base', 'byteswap', 'choose', 'clip', 'compress', 'conj', 'conjugate', 'copy', 'ctypes', 'cumprod', 'cumsum', 'data', 'diagonal', 'dot', 'dtype', 'dump', 'dumps', 'fill', 'flags', 'flat', 'flatten', 'getfield', 'imag', 'item', 'itemset', 'itemsize', 'max', 'mean', 'min', 'nbytes', 'ndim', 'newbyteorder', 'nonzero', 'partition', 'prod', 'ptp', 'put', 'ravel', 'real', 'repeat', 'reshape', 'resize', 'round', 'searchsorted', 'setfield', 'setflags', 'shape', 'size', 'sort', 'squeeze', 'std', 'strides', 'sum', 'swapaxes', 'take', 'tobytes', 'tofile', 'tolist', 'tostring', 'trace', 'transpose', 'var', 'view']

If I check the shape property, I will call it in this way:

var1.shape

However, when I call min property, I will call it in this way:

var1.min()

My question is how I can know the attribute is a variable, a function or an object (in this case I will use *var1.obj to print the contents). Thanks.

3
  • 1
    The term you are looking for is callable. var1.min works too, but the object that returns happens to be callable. Commented Sep 22, 2017 at 7:23
  • Try callable(var1.min) and callable(var1.shape), First will return True, second False. Commented Sep 22, 2017 at 7:26
  • I'm writing answer and almost complete. But it is closed first :( Commented Sep 22, 2017 at 7:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.