I work in a python shell and some weeks ago I have defined a variable which refers to a very important list. The shell stays always open, but I have forgotten this name. How to get a list of all global names I have ever defined?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
All of the globals or just the user-defined ones?
To get the things you have defined yourself, it appears that you can filter out from this list all key-value pairs whose keys do not match the regex
"__.*?__$".UPDATE
Here is a better answer:
Here I’ve excluded the special names beginning and ending with two underscores, so if you used them yourself they will not show. The
$at the end of the regex to prevent accepting__abc__1. Also I switched todir()which gets symbols in the current scope, not necessarily the global one, but it seems cleaner. It doesn’t add the leading list comprehension variable likeglobals()does.