主页
Python
Python zipimport 模块
demo_ref_module_zipimport_basic
运行 ❯
×
更改方向
保存代码
更改主题
import zipfile import zipimport # Create a ZIP with a simple module with zipfile.ZipFile('mymodules.zip', 'w') as z: z.writestr('greet.py', 'def hello(name): return f"Hello, {name}!"') # Import from ZIP using zipimport importer = zipimport.zipimporter('mymodules.zip') greet = importer.load_module('greet') print(greet.hello('Linus'))
Hello, Linus!