Is it possible to list the attributes/methods available to variables in mathematica in a similar way that python does? For instance in python I can run
my_var = "some string"
print(dir(my_var))
and see printed:
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
Which lets me know I can do things like my_var.startswith()
Whereas if I make a list:
my_var = []
print(dir(my_var))
I can see that a list has different methods/attributes associated with it like:
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
And in this instance I can call my_var.sort()
.
Is there an equivalent of this dir()
function in Mathematica? The closest I've found is Attributes[], which is still vastly different from my intended functionality.
Am I using improper terminology in my searches and this information isn't referred to as "methods" or "attributes" like it is in python? Thanks.
Definition
,Information
,DownValues
,UpValues
andOwnValues
. You are right, btw, in that Mathematica doesn't have a notion of "methods". Furthermore,Attributes
in Mathematica mean something quite different than in most other languages. See also: reference.wolfram.com/language/tutorial/… $\endgroup$