0

I want to allow user to make module file, if name isn't defined in Py3k already. (In it's portable installation). For ex, if user enters "ppp" i must check first, if module "ppp" exists in Py installation (it exists here!) and disallow this name. If he enters "my_name" i must allow it and if enters "ppp" or "json" I must disallow it.

Any way doing this check without doing "import" first? such import may take much memory. I only want to check if module name can be imported.

0

1 Answer 1

1

You can use the pkgutil module, something like this:

import pkgutil

def module_exists(m):
    for module_loader, name, ispkg in pkgutil.iter_modules():
        if name == m:
            return True
    return False
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.