Closed behrica closed 1 year ago
In python, the vars
function accomplishes this. During exploratory development I will often do
(import-python)
(python/vars some-py-obj)
To be fair it does not do the types, it's a KV map of names to values (not types), though you could valmap with python/type
Hmm, not sure I undertsnad the usage of python/vars
(import-python)
(def np (py/import-module "numpy"))
ser=> (-> (py/call-attr np "ones" [2 3]) (python/vars))
Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:708).
TypeError: vars() argument must have __dict__ attribute
In this case you would have to
(python/vars np/ndarray)
How do I know this?
In [1]: import numpy as np
In [2]: np.ones([2, 3])
Out[2]:
array([[1., 1., 1.],
[1., 1., 1.]])
In [3]: a = np.ones([2, 3])
In [4]: vars(a)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-ed1385268fe9> in <module>
----> 1 vars(a)
TypeError: vars() argument must have __dict__ attribute
In [5]: type(a)
Out[5]: numpy.ndarray
In [6]: vars(np.ndarray)
Out[6]:
mappingproxy({'__repr__': <slot wrapper '__repr__' of 'numpy.ndarray' objects>,
'__str__': <slot wrapper '__str__' of 'numpy.ndarray' objects>,
...snip...
Yes, I see. I can get the att-amp from something like:
(-> (py/call-attr np "ones" [2 3]) (python/type) (python/vars) ) )
Thanks.
The att-type-map function is not there anymore. We have now the "dir", but it returns less information. (only names, not types)
Is there a way to get the below list as well ?