TypeError:' abcmeta'在运行Pyspark的Pagerank时,对象是不可订阅的
我正在尝试运行 >实施页面排名。这是代码的一部分:
import re
import sys
from operator import add
from typing import Iterable, Tuple
from pyspark.resultiterable import ResultIterable
from pyspark.sql import SparkSession
def computeContribs(urls: ResultIterable[str], rank: float) -> Iterable[Tuple[str, float]]:
"""Calculates URL contributions to the rank of other URLs."""
num_urls = len(urls)
for url in urls:
yield (url, rank / num_urls)
def parseNeighbors(urls: str) -> Tuple[str, str]:
"""Parses a urls pair string into urls pair."""
parts = re.split(r'\s+', urls)
return parts[0], parts[1]
但是当我运行它时,我会得到这个错误:
10 from collections.abc import Mapping
11
---> 12 def computeContribs(urls: ResultIterable[str], rank: float) -> Iterable[Tuple[str, float]]:
13 """Calculates URL contributions to the rank of other URLs."""
14 num_urls = len(urls)
TypeError: 'ABCMeta' object is not subscriptable
我该怎么办?我不知道为什么在定义函数时应该定义类型。
I'm trying to run this implementation of Page Rank. This is a part of the code:
import re
import sys
from operator import add
from typing import Iterable, Tuple
from pyspark.resultiterable import ResultIterable
from pyspark.sql import SparkSession
def computeContribs(urls: ResultIterable[str], rank: float) -> Iterable[Tuple[str, float]]:
"""Calculates URL contributions to the rank of other URLs."""
num_urls = len(urls)
for url in urls:
yield (url, rank / num_urls)
def parseNeighbors(urls: str) -> Tuple[str, str]:
"""Parses a urls pair string into urls pair."""
parts = re.split(r'\s+', urls)
return parts[0], parts[1]
But when I run it, I get this error:
10 from collections.abc import Mapping
11
---> 12 def computeContribs(urls: ResultIterable[str], rank: float) -> Iterable[Tuple[str, float]]:
13 """Calculates URL contributions to the rank of other URLs."""
14 num_urls = len(urls)
TypeError: 'ABCMeta' object is not subscriptable
What should I do? I have no idea why should I define types when defining functions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论