When the Python file is executed, it says that the first imported module is loaded and executed.
So I did an experiment myself.
Once I import sys, I just received the value as input(), which is the Python built-in function.
import tracemalloc,sys
def app():
a = input()
# starting the monitoring
tracemalloc.start()
app()
print(tracemalloc.get_traced_memory())
tracemalloc.stop()
Then output is (64, 72).
What's interesting is that the memory usage was the same when I did import sys and when I didn't.
So I modified some of the codes as below.
import tracemalloc,sys
def app():
a = sys.stdin.readline()
# starting the monitoring
tracemalloc.start()
app()
print(tracemalloc.get_traced_memory())
tracemalloc.stop()
This time, of course, It use a lot more memory.
(51, 12661)
This means that the sys module has been loaded into memory.
Python is said to be an interpreter language, so can Python know in advance to use sys or not?
Or is the sys module loaded in memory when it is used? Like a dll?
Or is it wrong to explain that the Python file is loaded and executed first?