To use any package in your code, you must first make it available. You have to import this. You cannot use anything in Python until it is defined. Some things are built in, for example basic types (like int, float, etc.) can be used at any time.
But most of the things you want to do will take a little more than that. For example, if you want to calculate the cosine of 1 radian, if you run math.cos (0), you will get a NameError since the math is undefined.
Example
You must tell python to first import this module into your code so you can use it.
""" math.cos (0) Traceback (most recent call last): File ""stdin"", line 1, in "module" NameError: name ’math’ is not defined""" import math""" math.cos (0) 1.0
If you have your own Python files that you want to import, you can use the import statement like this:
""" import my_file # assuming you have the file, my_file.py in the current directory. # For files in other directories, provide path to that file, absolute or relative.< / p>