在python的main()函数中导入类

2024-09-30 12:19:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在我的main()方法(sender模块中的入口点)中导入一个模块,并将用户输入参数传递给它。该模块将创建一个json数据结构。但是,我无法导入此模块。我的IDE无法解析它。 主要功能如下:

def main():
    from directioncontroller import controller

    args = create_parser().parse_args()
    json_message(args.direction)
    print("Sending direction %s" % args.direction )

以及控制器模块:

import json

def json_message(direction):
    data = {}
    data['instruction'] = 'direction'
    json_data = json.dumps(data)
    return json_data

我已按以下方式在安装文件中指定了入口点:

from setuptools import setup, find_packages

with open('README.rst', 'r') as f:
    readme = f.read()

setup(
    name='practice',
    version='0.1.0',
    description='Direction Controller',
    long_description=readme,
    author='user',
    author_email='user@email.com',
    packages=find_packages('src'),
    package_dir={'':'src'},
    install_requires=[],
    entry_points={
        'console_scripts': [
            'directioncontroller=directioncontroller.sender:main'
        ]
    }

)

为什么我的包中没有标识类?你知道吗


Tags: 模块fromimportjsonmessagedatamainpackages

热门问题