Let's assume I have the following file structure:
data.py
foo = [] bar = [] abc = "def"
core.py
import data # do something here # # a = ... print a # ['foo', 'bar', 'abc']
I need to get all the variables defined in data.py file. How can I achieve that? I could use dir(), but it returns all the attributes of the module including __name__ and so on.
dir()
__name__
print [item for item in dir(adfix) if not item.startswith("__")]
Is usually the recipe for doing this, but it begs the question.
2.1m questions
2.1m answers
60 comments
57.0k users