FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

How to check whether a Python module is installed




Just bumped into this nice Python tip here and tried it using my Python Expression Evaluator.
Works nicely to test whether a needed Python module is installed. If __import__ doesn't return anything then the specified Python module can be imported, otherwise an error message "No module named ..." will be returned.

Is it possible to generate a list of modules ?
Yep, sort of: try help("modules") ...



1 blog comments below

Python modules provide standard functions you ( and many others ) need to write a program, like for instance:

    . converting and doing math with dates and times
    . reading / writing XML or HTML files
    . using regular expressions
    . accessing operating system and using its feature, like e.g. reading / writing files or issuing system commands
    . web / html / cgi support ( to write web applications )
    . support to implement GUIs
    . support to work with databases like mySQL or SQLite

... and many many more.
Thus in that sense they can be seen as extensions or add-ons of native Python.

In a more general sense whenever you write re-usable code / functions you might want to implement those as modules for easy re-use by yourself or others. See http://docs.python.org/2/tutorial/modules.html for a more sophisticated explanation ...
amagard on Sat Aug 31, 2013 1:50 pm



FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.