pyspark.Broadcast.load ¶
-
Broadcast.
load
( file : BinaryIO ) → T [source] ¶ -
从打开的文件或套接字中读取值的序列化表示。
- Parameters
-
-
file
BinaryIO
-
读取序列化值的文件或套接字。
-
file
- Returns
-
- T
-
其中指定的对象层次结构是从对象的序列化表示中重新构建的。
示例
>>> import os >>> import tempfile
>>> b = spark.sparkContext.broadcast([1, 2, 3, 4, 5]) >>> c = spark.sparkContext.broadcast(1)
从打开的临时文件中读取值的序列化表示。
>>> with tempfile.TemporaryDirectory() as d: ... path = os.path.join(d, "test.txt") ... with open(path, "wb") as f: ... b.dump(b.value, f) ... with open(path, "rb") as f: ... c.load(f) [1, 2, 3, 4, 5]