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 433465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:10:37+00:00 2026-05-12T20:10:37+00:00

I am in the process of coding an app which has to get the

  • 0

I am in the process of coding an app which has to get the metadata (author,version..etc) out of several modules (.py files) and display them. The user selects a script and the script is executed. (New scripts can be added and old ones be taken of from the target folder just like a plugin system).

Firstly I import a script and I take out the metadata, then I go for the next.
But I want to de-import all the other modules except for the one that the user has selected.

How can I implement this?

I tried these

1. del module
2. del sys.modules['module']

The latter did not work. I tried #python and got the answer that it was not good to de-import modules, but I want to know a clean way of implementing this. Any ideas/suggestions would help.

  • 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-12T20:10:37+00:00Added an answer on May 12, 2026 at 8:10 pm

    I think this post should help you.

    To secure the availability of this information (in case the link dies or something similar), below is the original message from the tutor mailing list:


    On 8/14/06, Dick Moores wrote:

    Actually, my question is, after using IDLE to do some importing of
    modules and initializing of variables, how to return it to it’s
    initial condition without closing and reopening it.

    So, for example after I’ve done

    >>> import math, psyco
    >>> a = 4**23
    

    How can I wipe those out without closing IDLE?
    (I used to know how, but I’ve forgotten.)

    Hi Dick,

    Usually this entails removing from the "module registry and removing
    references to it in the code. If you have a really well used module (like
    one with config parameters imported into every module), then you’ll have an
    additional step of removing it from every module. Also, if you have use
    "from psyco import …", then you will not be able to free up the module and
    the reference to the module easily (is it from that module, or imported from
    a third module? see "if paranoid: code below).

    The function below deletes a module by name from the Python interpreter, the
    "paranoid" parameter is a list of variable names to remove from every other
    module (supposedly being deleted with the module). Be VERY careful with the
    paranoid param; it could cause problems for your interpreter if your
    functions and classes are named the same in different modules. One common
    occurrance of this is "error" for exceptions. A lot of libraries have one
    "catch-all" exception called "error" in the module. If you also named your
    exception "error" and decided to include that in the paranoid list… there
    go a lot of other exception objects.

    def delete_module(modname, paranoid=None):
        from sys import modules
        try:
            thismod = modules[modname]
        except KeyError:
            raise ValueError(modname)
        these_symbols = dir(thismod)
        if paranoid:
            try:
                paranoid[:]  # sequence support
            except:
                raise ValueError('must supply a finite list for paranoid')
            else:
                these_symbols = paranoid[:]
        del modules[modname]
        for mod in modules.values():
            try:
                delattr(mod, modname)
            except AttributeError:
                pass
            if paranoid:
                for symbol in these_symbols:
                    if symbol[:2] == '__':  # ignore special symbols
                        continue
                    try:
                        delattr(mod, symbol)
                    except AttributeError:
                        pass
    

    Then you should be able to use this like:

    delete_module('psyco')
    

    or

    delete_module('psyco', ['Psycho', 'KillerError'])
    # only delete these symbols from every other module
    # (for "from psyco import Psycho, KillerError" statements)
    

    -Arcege

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

Sidebar

Related Questions

I'm in the process of refactoring some code which includes moving folders around, and
A Windows process created from an exe file has access to the command string
I'm in the process of weeding out all hardcoded values in a Java library
I'm currently trying to get the output of an executable console-app into an other
I am working on an existing ASP.NET MVC app that started small and has
On windows, each thread has a message queue, and each message queue will process
Hii I was coding for an application that shows the list of running process
I'm coding a C# wpf app and I need to block processing in order
I'm in the process of learning WPF coming from WinForms development. I have a
Java process control is notoriously bad - primarily due to inadequate support by the

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.