Quick question, what is the difference between
import file
import .file
Can someone explain the difference between them? Can someone explain all kinds of importing to me?
Quick question, what is the difference between
import file
import .file
Can someone explain the difference between them? Can someone explain all kinds of importing to me?
import .file
It's the new syntax for explicit relative imports. It means import from the current package. This is the current namespace or package directory.
You can use more than one dot, referring not to the current package but its parent(s). This should only be used within packages, in the main module.
There are two ways to use functions of other modules.
First is importing the whole Module.
import math #this will import math module
print(math.sqrt(4)) #Using function of math module
Second Method is by importing the function not module
from math import sqrt #this will import sqrt function not full module
print(sqrt(4)) #Using function of math module
Note some more suggestions 1. you can also import module and function by using as and import it under n alias name, Example import math as ilovemaths #importing under alias name print(ilovemaths.sqrt(4)) #using the function of module.