Search code examples
pythonimportdeap

What dose this statement mean in python deap package?


There are some statements in the init.py file of python DEAP package, such as:

from .crossover import *

Is this means import all function from crossover.py? So why there is a "." in front of crossover. It would be so much appreciated that if somebody could help me understand the meaning of . and * in the statement.


Solution

  • Python imports names from files and gives you access to them in the interpreter or other files. This is all a part of the Module system used in Python.

    The star (asterisk) means "add all of the names from that file to my current working list of names."

    The '.' in front of crossover is a relative import. This means, relative to your current location (in an interpreter or a file) find a file called "crossover"

    All together:

    Import all of the names of in a module called crossover that is located within the current directory.