我有一个作为模块运行的烧瓶应用程序。结构看起来像这样
app/
__init.py
__main__.py
app.py
cli.py
__main__.py
看起来像这样:
from . import cli
cli.main()
cli.py看起来像这样:
import argparse
import ConfigParser as configparser
import sys
from . import app
def command_line_arguments():
parser = argparse.ArgumentParser(description='application')
parser.add_argument(
'-c', '--config-file', type=str,
help='Load settings from the chosen configuration file')
return parser.parse_args()
def main():
"Run the app with the configuration chosen in command_line_arguments()"
options = command_line_arguments()
app = app.App(options.config_file)
try:
app.run(
host=app.host,
port=8000)
except KeyboardInterrupt:
pass
该应用程序运行良好,但如果我尝试在运行参数中设置debug = true(或初始化应用程序时,我尝试运行应用程序时出现以下错误:
Traceback (most recent call last):
File "" line 1, in <module>
from . import cli
ValueError: Attempted relative import in non-package
有关如何使用这种设置进行调试的任何想法?