Forum: Poser Python Scripting


Subject: Useful Code Snippets

structure opened this issue on Jun 27, 2019 ยท 94 posts


structure posted Mon, 04 January 2021 at 8:58 AM Forum Coordinator

Check if a module exists before trying to import it.

from pkgutil import iter_modules


class basic_functions:
    def module_exists( self, module_name):
        return module_name in (name for loader, name, ispkg in iter_modules())

if basic_functions().module_exists( "poser" ):
    import poser
else:
    if basic_functions().module_exists( "POSER_FAKE"):
        import POSER_FAKE as poser

Locked Out