1

How can I get all class, object, function names in current namescope in Python? How can I differentiate between them(e.g. get only class names)?

Tim Tim
  • 13
  • 3

1 Answers1

0

Use help() or dir().
You can dump the output into a list of strings and read from there too to differentiate what you require

ycx
  • 3,155
  • 3
  • 14
  • 26
  • Well, dir() only tells me names declared whithin current scope, not all of them which I can use, if I understand correctly the results of my tests – Tim Tim Dec 23 '18 at 18:57
  • You can `import` your module and do a `print(dir(module))`. I don't see the issue here with scope – ycx Dec 23 '18 at 19:00
  • @TimTim `dir()` may be what you are looking for. The difference between `dir()` and `locals()` is that `dir()` returns a list of the names, and `locals()` is a dictionary with the names as keys and the values are what these names reference (primitive values, functions, modules etc). Confirm this with `print(set(dir()) == set(locals().keys()))` which prints `True` – DeepSpace Dec 23 '18 at 19:00
  • ok, got that, I'll look into it, thanks – Tim Tim Dec 23 '18 at 19:10