I have a scrip 'xyz.py' that I'm importing as a module for another script (Main.py). Everything in xyz.py is inside of a class that I call in Main.py. Both, xyz.py and Main.py share the same import statements: "xml.etree.ElementTree"; "Tkinter"; "cv2"; "tkFileDialog"; "tkfd"; "from PIL import Image"; "ImageTk"; "os"
I noticed that when I run in Main.py the class having all the methods and statements of xyz.py, they run faster as a module than as the main script.
Is there a general fact behind this observation that I could use to speed up other stuff? Thank you.
PS: I didn't provide the code because it sums up to >400 lines, and I don't know exactly what I'm supposed to be looking at, so I'm not able to take a small and  relevant sample.
When a python program runs, the main script is always passed through the interpreter.  When a module is imported, however, python checks its cache ( subdirectory named __pycache__) where it stores modules that have previously been compiled to bytecode.  If the date of the cached copy matches the date of the source code date, it uses the cached version.  That probably accounts for what you are seeing.
why does a script run faster as a module?