Fundamentals 3 min read

Understanding Python import Statements: Importing Modules and Specific Members

This article explains the two primary Python import syntaxes—importing an entire module versus importing selected members—detailing their differences, usage of aliases, multiple module imports, and includes runnable code examples that illustrate how each form affects name resolution.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Understanding Python import Statements: Importing Modules and Specific Members

Python provides two main forms of the import statement: import module_name [as alias], ... to import an entire module, and from module_name import member_name [as alias], ... to import specific members.

The first form makes all module members accessible via the module name (or its alias), while the second allows direct use of selected members without a prefix, though from module_name import * is discouraged.

Examples demonstrate importing the whole sys module and accessing sys.argv[0] , assigning an alias with import sys as s , and importing multiple modules using import sys, os to access os.sep .

Running these snippets shows the expected output, illustrating how the import style influences name resolution in Python programs.

programmingfundamentalsModuleSyntax@Import
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.