Back
Close

Computing with Data

elgeish
33.6K views
Previous: Objects Next: Executing Shell Commands

Importing Modules

A Python module is a code object loaded into the Python program by the process of importing. Suppose we have a module file my_vars.py, the definitions in this file can be accessed in a different file using the appropriate import command:

import my_vars
# accessing variables in my_vars module
area = my_vars.LENGTH * my_vars.WIDTH
# the following imports the module using an alias
import my_vars as mv
area = mv.LENGTH * mv.WIDTH
# the following makes the definition x in the current module
# accessible without the need for its prefix
from my_vars import LENGTH, WIDTH
area = LENGTH * WIDTH
from my_vars import *
area = LENGTH * WIDTH
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants