如何从python模块调用数据/变量?

时间:2018-06-21 14:24:12

标签: python

我创建了一个python模块,其中存储了一个变量。当我运行时:help(connections_and_variables.connections_and_variables)

我可以在“数据”部分看到变量(dw_path)。

如何在读取模块的脚本中调用它?

NAME
    connections_and_variables.connections_and_variables - Created on Fri Jun 15 10:19:46 2018

FILE
    c:\users\USER\documents\data-warehouse\connections_and_variables\connections_and_variables.py

DESCRIPTION
    @author: USER

FUNCTIONS
    db(name)

    db_engine(name)

DATA
    dw_path = r'C:\Users\USER\Documents\data-warehouse'

1 个答案:

答案 0 :(得分:1)

就像您可以从模块访问其他任何内容一样:

import connections_and_variables.connections_and_variables
print(connections_and_variables.connections_and_variables.dw_path)

或者:

from connections_and_variables import connections_and_variables
print(connections_and_variables.dw_path)

或者:

from connections_and_variables.connections_and_variables import dw_path
print(dw_path)