I work in a Python shell. In order to produce a list of all global names I use dir(), but it generates a very long list, which I would like to filter. I am interested only in the names which begin with ‘f’ and end with digits. Sometimes I also need only user-defined names, no __*__ names. Is there any grep-like method in a Python shell to filter its output?
I work in a Python shell. In order to produce a list of all
Share
[n for n in dir() if re.match("f.*[0-9]$", n)]I set my PYTHONSTARTUP environment variable to point to
~/.startup.pywhich contains:Now I always have a few handy modules imported, and I have shortcuts available for things I often do in the shell.