... Der Interpreter Suchvorgänge
nach einem gebauten -in Modul mit diesem Namen. Diese Modulnamen sind in
sys.builtin_module_names aufgeführt. Wenn nicht gefunden, sucht es dann nach einer Datei
namens spam.py in einer Liste der Verzeichnisse, die vom variablen sys.path angegeben sind. />
- Das Verzeichnis, das das Eingabeskript enthält (oder das aktuelle Verzeichnis
Wenn keine Datei angegeben ist). < /p>
< /li> < Br /> PythonPath (eine Liste von Verzeichnisnamen mit derselben Syntax wie der Variable -Pfad
Shell). >
Code: Select all
>>> sys.builtin_module_names
('_abc', '_ast', '_codecs', '_collections', '_functools', '_imp', '_io', '_locale', '_operator', '_signal', '_sre', '_stat', '_string', '_suggestions', '_symtable', '_sysconfig', '_thread', '_tokenize', '_tracemalloc', '_typing', '_warnings', '_weakref', 'atexit', 'builtins', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'posix', 'pwd', 'sys', 'time')
>>> 'os' in sys.builtin_module_names
False
Code: Select all
#os.py
def fun():
print("Custom os called!")
Code: Select all
#test.py
import sys
print("os in sys.builtin_module_names -", 'os' in sys.builtin_module_names)
print("First directory on sys -", sys.path[0])
import os
print("source file of the imported os -", os.__file__)
print(os.fun())
Code: Select all
> python3 test.py
os in sys.builtin_module_names - False
First directory on sys - /Users/dhruv/Documents/test
source file of the imported os - /opt/homebrew/Cellar/python@3.13/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/os.py
Traceback (most recent call last):
File "/Users/dhruv/Documents/test/test.py", line 9, in
print(os.fun())
^^^^^^
AttributeError: module 'os' has no attribute 'fun'