跳转到主要内容

将任意Python源代码导入为Python模块

项目描述

stringimporter

stringimporter 允许您将原始字符串作为真正的Python模块导入

如何使用

您可以阅读测试(在tests目录中)或复制以下代码。

import stringimporter

module_from_thin_air = """
def multiply_by_2():
    return lambda x: 2*x"""

loader, mymodule = stringimporter.import_str('yihaaa', module_from_thin_air)

hello_2 = mymodule.multiply_by_2()("hello ")

依赖项

兼容性

Python 3。我不知道(目前)如何在Python 2.7上模拟importlib.abc.SourceLoader。

项目详情


下载文件

下载适合您平台的应用程序文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分发

stringimporter-0.1.4.tar.gz (1.8 kB 查看哈希值)

上传时间:

构建分发

stringimporter-0.1.4-py2.py3-none-any.whl (2.7 kB 查看哈希值)

上传时间: Python 2 Python 3

由以下支持