Dec-29-2021, 09:22 PM
Without a reason it is difficult answer your question. A module can ask for it's filename and even get hold of it's own code. You could then parse the code to learn everything you want. But that would be hard and I don't know why you would ever want to do it.
You could use locals() to get a dictionary of all the variables that exist in the current scope/namespace. You could parse the keys to select variables to collect in you list. You could use dir() to get similar info in the form of a list.
The statement "There are no stupid questions" is a lie. This is a stupid question. It is stupid because it is pointless. If you can think of a reason why you might want to collect a bunch of variables into a collection it ceases being pointless and stupid. If you post the reason why you want to know this (other than curiosity) it provides a context that will help others understand and answer your question. "I want to open up a window that shows me the values of all my program variables. How could I do that?" is not a stupid, pointless question. Do you have a question like that?
You could use locals() to get a dictionary of all the variables that exist in the current scope/namespace. You could parse the keys to select variables to collect in you list. You could use dir() to get similar info in the form of a list.
The statement "There are no stupid questions" is a lie. This is a stupid question. It is stupid because it is pointless. If you can think of a reason why you might want to collect a bunch of variables into a collection it ceases being pointless and stupid. If you post the reason why you want to know this (other than curiosity) it provides a context that will help others understand and answer your question. "I want to open up a window that shows me the values of all my program variables. How could I do that?" is not a stupid, pointless question. Do you have a question like that?