pyspark中的导入模块

时间:2018-06-21 16:09:05

标签: python apache-spark pyspark

我的项目目录如下所示

Project 
   cfg
        config.py
       __init__.py
   lib 
       script.py
       __init__.py 

在script.py中,我将config.py导入为

sc.addFile("<Project root>/cfg/config.py")
import config

这里是硬编码路径,我想避免这种硬编码。最好的方法是什么?

1 个答案:

答案 0 :(得分:0)

执行此操作的Python方法可能是将[ [ { "id": "one", "color": "red" }, { "id": "two", "color": "blue" }, { "id": "three", "color": "green" } ], [ { "id": "two", "color": "blue" }, { "id": "three", "color": "green" }, { "id": "four", "color": "black" } ], [ { "id": "three", "color": "green" }, { "id": "four", "color": "black" }, { "id": "five", "color": "red" } ], [ { "id": "four", "color": "black" }, { "id": "five", "color": "red" }, { "id": "six", "color": "blue" } ], [ { "id": "five", "color": "red" }, { "id": "six", "color": "blue" }, { "id": "seven", "color": "green" } ], [ { "id": "six", "color": "blue" }, { "id": "seven", "color": "green" }, { "id": "eight", "color": "black" } ] ] 添加到__init__.py,然后使用相对导入:

Project