Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6559757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:22:15+00:00 2026-05-25T13:22:15+00:00

I work in a Python shell. In order to produce a list of all

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:22:15+00:00Added an answer on May 25, 2026 at 1:22 pm

    [n for n in dir() if re.match("f.*[0-9]$", n)]

    I set my PYTHONSTARTUP environment variable to point to ~/.startup.py which contains:

    # Ned's startup.py file, loaded into interactive python prompts.
    
    print("(.startup.py)")
    
    import datetime, os, pprint, re, sys, time
    
    print("(imported datetime, os, pprint, re, sys, time)")
    
    def dirx(thing, regex):
        return [ n for n in dir(thing) if re.search(regex, n) ]
    
    pp = pprint.pprint
    

    Now I always have a few handy modules imported, and I have shortcuts available for things I often do in the shell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Matplotlib and Pylab don't work in Python CGI. But the same combination is working
In Python IDLE Shell it seems I cannot use a compound conditional expression and
Why does Import[!python --version, Text] work on the commandline but not in the frontend
I am trying to use the help() function in the Python interactive shell to
I work in a python shell and some weeks ago I have defined a
this might be a very simple question but I need your help. I work
Why doesn't the following work (Python 2.5.2)? >>> import datetime >>> class D(datetime.date): def
Does BeautifulSoup work with Python 3? If not, how soon will there be a
Has anyone seen anything in Tix work under python 3.0? I've tried to work
I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.