是否有可能以返回的方式结束python模块导入?

sor*_*rin 7 python python-module

我想知道是否有一种编写以下模块代码的方法,而无需在整个模块代码中添加另一个缩进级别.

# module code
if not condition:
    # rest of the module code (big)
Run Code Online (Sandbox Code Playgroud)

我正在寻找这样的东西:

# module code
if condition:
    # here I need something like a `return`
# rest of the module code (big)
Run Code Online (Sandbox Code Playgroud)

注意,我不想抛出异常,导入应该正常传递.

Unc*_*eiv 5

我不知道有任何解决方案,但我想你可以将所有代码放在一个内部模块中,如果条件不满足则导入.