Import keyword in the Python program [closed]

0

How does the operating system know how to handle the keyword "import" in a python program? In other words, how does the referred module know how to "import"?

    
asked by Cody Rutscher 15.11.2018 в 12:29
source

1 answer

0

The operating system has nothing to do with the import process.

The python interpreter has a series of complicated rules about how to interpret the reserved word import . In essence it is that, when you find import nombre , look for a file called nombre.py (or a folder called nombre , containing inside a file called __init__.py ) in a series of preconfigured folders and in other that can be specified by PYTHONPATH .

The whole story is much longer and more complicated , but you better edit the question and add more questions concrete if you need to know more.

PS: If you have three free hours you can see this David Beazly video where he explains all the ins and outs, probably much more than you need (or would want) to know. I still do not understand half ...

    
answered by 15.11.2018 / 13:51
source