Possible to output dir() in python as a vertical list?
python
Solution
It's just a list, so you can loop over it too:
for entry in dir(obj):
print repr(entry)
or you could use `pprint.pprint()` to have the list formatted 'prettily' for you.
Demo on the `pprint` module itself:
>>> import pprint
>>> pprint.pprint(dir(pprint))
['PrettyPrinter',
'_StringIO',
'__all__',
'__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'_commajoin',
'_id',
'_len',
'_perfcheck',
'_recursion',
'_safe_repr',
'_sorted',
'_sys',
'_type',
'isreadable',
'isrecursive',
'pformat',
'pprint',
'saferepr',
'warnings']
Problem
I'm using the `dir(variable)` command in Python to get all the attributes and methods of `variable`. The output looks something like this: `['attribute', 'attribute', 'method', 'attribute', 'method', etc.]`; i.e., the output is horizontal so it's hard to peruse. Is there a way to make `dir()` output a vertical list, like this: ``` 'attribute', 'attribute', 'method', 'attribute', 'method', etc. ```