There is a script in the working directory which I can access with:
from . import core.py
I would also like to import * from core.py. How would I write this in Python?
The difference between import and from import in Python is: import imports the whole library. from import imports a specific member or members of the library.
Using import * in python programs is considered a bad habit because this way you are polluting your namespace, the import * statement imports all the functions and classes into your own namespace, which may clash with the functions you define or functions of other libraries that you import.
It just means that you import all(methods, variables,...) in a way so you don't need to prefix them when using them.
Importing Modules To make use of the functions in a module, you'll need to import the module with an import statement. An import statement is made up of the import keyword along with the name of the module. In a Python file, this will be declared at the top of the code, under any shebang lines or general comments.
see https://docs.python.org/2/tutorial/modules.html
In section 6.4.2. Intra-package References:
from . import core
from .. import core
from ..other import core
Note: Starting with Python 2.5, in addition to the implicit relative imports, you can write explicit relative imports with the from module import name form of import statement. These explicit relative imports use leading dots to indicate the current and parent packages involved in the relative import. From the surround module.
To keep the exact same semantics as from . import core
, you'll want to do:
from .core import *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With