本文整理汇总了Python中sortedcontainers.SortedSet.extend方法的典型用法代码示例。如果您正苦于以下问题:Python SortedSet.extend方法的具体用法?Python SortedSet.extend怎么用?Python SortedSet.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedSet
的用法示例。
在下文中一共展示了SortedSet.extend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import extend [as 别名]
class FileReference:
"""A class that manages n-triple files.
This class stores inforamtation about the location of a n-triple file and is
able to add and delete triples to that file.
"""
def __init__(self, path, content):
"""Initialize a new FileReference instance.
Args:
filelocation: A string of the filepath.
filecontentinmem: Boolean to decide if local filesystem should be used to
or if file content should be kept in memory too . (Defaults false)
Raises:
ValueError: If no file at the filelocation, or in the given directory + filelocation.
"""
if isinstance(content, str):
new = []
for line in content.splitlines():
new.append(' '.join(line.split()))
content = new
self._path = path
self._content = SortedSet(content)
self._modified = False
@property
def path(self):
return self._path
@property
def content(self):
return "\n".join(self._content) + "\n"
def add(self, data):
"""Add a triple to the file content."""
self._content.add(data)
def extend(self, data):
"""Add triples to the file content."""
self._content.extend(data)
def remove(self, data):
"""Remove trple from the file content."""
try:
self._content.remove(data)
except KeyError:
pass