Python软件开发中的stdafx.h等效项

问题描述 投票:1回答:1

当软件变得越来越大时,可能很难为每个“ .py”文件提供一个清晰的导入列表。因此,我想到的问题是,是否有任何最佳实践。为了进一步说明这个问题,假设我们有5个文件,它们使用sklearn,numpy等。现在,可以创建类似于我们在C ++中所做的那样的所谓的“ stdafx.py”文件,而不是使用以下方法在5个文件代码的开头导入每个软件包:import stdafx.py *其中stdafx.py是所有这些软件包的批处理。换句话说,它将包含:

        -----------------------------stdafx.py------------------------------------
import numpy as np
import pandas as pd
from tensorflow import keras
from X import Y
.
.
.
python software-design stdafx.h
1个回答
0
投票

您可以这样操作:

stdafx.py

import collections
import itertools
import functools

another_module.py

from stdafx import *

print(collections, itertools, functools)  # all modules are available
© www.soinside.com 2019 - 2024. All rights reserved.