Python Flashcards
Explain relative imports
dir1 -file1.py dir2 -file2.py main.py
if running main.py from the root dir, then main will be able to access all the dirs/imports bc they are on its path. When you run main, you can see with sys.path that the root dir is on its path, meaning all dirs and files on that root dir are accessible.
If you run file2.py from the root dir, file2 will only have dir2 on its path, so it will not be able to see dir1 or main or other files that are its parent
to fix this, if you are running with rootdir as the current working directory and run file2, then you will need to add sys.path.append(“.”) This will append the current working directory and since that is the rootdir, you will get all files on the root dir.
If your current workign directory is dir2 and you run file2, then you need to append sys.path.append(“..”) because to get the root directory from your current working directory, you need to move up 1 directory.
get max, min int values
bonus, are there long values in python 3?
import sys
sys. maxsize
- sys.maxsize-1
there are no longs in python 3