python import file from same level 1

python import file from same level

#Example of tree:

# 		main.py
# 		package/
#				asset1.py
#				asset2.py
#				asset3.py

#If you want to import asset2 into asset1 do this in asset1.py :
import .asset2

Here is what the above code is Doing:
1. The . tells Python to look for the module in the current directory.
2. The .. tells Python to look for the module in the parent directory.
3. The … tells Python to look for the module in the grandparent directory.
4. The …. tells Python to look for the module in the great-grandparent directory.
5. And so on.

Similar Posts