Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Python: Find the available built-in modules

Python Basic: Exercise-78 with Solution

Write a Python program to find the available built-in modules.

Sample Solution-1:

Python Code:

import sys
import textwrap
module_name = ', '.join(sorted(sys.builtin_module_names))
print(textwrap.fill(module_name, width=70))

Sample Output:

_ast, _bisect, _codecs, _collections, _datetime, _elementtree,                                                
_functools, _heapq, _imp, _io, _locale, _md5, _operator, _pickle,                                             
_posixsubprocess, _random, _sha1, _sha256, _sha512, _signal, _socket,                                         
_sre, _stat, _string, _struct, _symtable, _thread, _tracemalloc,                                              
_warnings, _weakref, array, atexit, binascii, builtins, errno,                                                
faulthandler, fcntl, gc, grp, itertools, marshal, math, posix, pwd,                                           
pyexpat, select, spwd, sys, syslog, time, unicodedata, xxsubtype,                                             
zipimport, zlib 

Sample Solution-2:

Python Code:

 help('modules')

Sample Output:

Please wait a moment while I gather a list of all available modules...

/usr/local/lib/python3.6/dist-packages/Bio/GA/__init__.py:14: BiopythonDeprecationWarning: Bio.GA has been deprecated, and we intend to remove it in a future release of Biopython. Please consider using DEAP instead.  If you would like to continue using Bio.GA, please contact the Biopython developers via the mailing list or GitHub.
  BiopythonDeprecationWarning)
/usr/local/lib/python3.6/dist-packages/Bio/NeuralNetwork/__init__.py:15: BiopythonDeprecationWarning: Bio.NeuralNetwork has been deprecated, and we intend to remove it in a future release of Biopython. Please consider using scikit-learn or TensorFlow instead.  If you would like to continue using Bio.NeuralNetwork, please contact the Biopython developers via the mailing list or GitHub.
  BiopythonDeprecationWarning)
/usr/local/lib/python3.6/dist-packages/Bio/SearchIO/__init__.py:211: BiopythonExperimentalWarning: Bio.SearchIO is an experimental submodule which may undergo significant changes prior to its future official release.
  BiopythonExperimentalWarning)
/usr/local/lib/python3.6/dist-packages/Bio/codonalign/__init__.py:27: BiopythonExperimentalWarning: Bio.codonalign is an experimental module which may undergo significant changes prior to its future official release.
  BiopythonExperimentalWarning)
/usr/local/lib/python3.6/dist-packages/Bio/phenotype/__init__.py:101: BiopythonExperimentalWarning: Bio.phenotype is an experimental submodule which may undergo significant changes prior to its future official release.
  BiopythonExperimentalWarning)
/usr/local/lib/python3.6/dist-packages/bokeh/util/deprecation.py:34: BokehDeprecationWarning: 
The bokeh.charts API has moved to a separate 'bkcharts' package.

This compatibility shim will remain until Bokeh 1.0 is released.
After that, if you want to use this API you will have to install
the bkcharts package explicitly.

  warn(message)
/usr/local/lib/python3.6/dist-packages/bokeh/util/deprecation.py:34: BokehDeprecationWarning: MPL compatibility can no longer be successfully maintained, and is now deprecated. All MPL compat functions will be removed completely on the release of Bokeh 1.0. See https://bokeh.pydata.org/en/latest/docs/releases/0.12.5.html for more information
  warn(message)

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to test whether the system is a big-endian platform or little-endian platform.
Next: Write a Python program to get the size of an object in bytes.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Python: Tips of the Day

Find current directory and file's directory:

To get the full path to the directory a Python file is contained in, write this in that file:

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))

(Note that the incantation above won't work if you've already used os.chdir() to change your current working directory, since the value of the __file__ constant is relative to the current working directory and is not changed by an os.chdir() call.)

To get the current working directory use

import os
cwd = os.getcwd()

Documentation references for the modules, constants and functions used above:

  • The os and os.path modules.
  • The __file__ constant
  • os.path.realpath(path) (returns "the canonical path of the specified filename, eliminating any symbolic links encountered in the path")
  • os.path.dirname(path) (returns "the directory name of pathname path")
  • os.getcwd() (returns "a string representing the current working directory")
  • os.chdir(path) ("change the current working directory to path")

Ref: https://bit.ly/3fy0R6m