本文整理汇总了Python中collections.html方法的典型用法代码示例。如果您正苦于以下问题:Python collections.html方法的具体用法?Python collections.html怎么用?Python collections.html使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections
的用法示例。
在下文中一共展示了collections.html方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _bibFormatter
# 需要导入模块: import collections [as 别名]
# 或者: from collections import html [as 别名]
def _bibFormatter(s, maxLength):
"""Formats a string, list or number to make it good for a bib file by:
* if too long splits up the string correctly
* tries to use the best quoting characters
* expands lists into ' and ' seperated values, as per spec for authors field
Note, this does not escape characters. LaTeX may have issues with the output
Max length splitting derived from https://www.cs.arizona.edu/~collberg/Teaching/07.231/BibTeX/bibtex.html
"""
if isinstance(s, list):
s = ' and '.join((str(v) for v in s))
elif not isinstance(s, str):
s = str(s)
if len(s) > maxLength:
s = s.replace('"', '')
s = [s[i * maxLength: (i + 1) * maxLength] for i in range(len(s) // maxLength )]
s = '"{}"'.format('" # "'.join(s))
elif '"' not in s:
s = '"{}"'.format(s)
else:
s = s.replace('{', '\\{').replace('}', '\\}')
s = '{{{}}}'.format(s)
return s
示例2: _do_add
# 需要导入模块: import collections [as 别名]
# 或者: from collections import html [as 别名]
def _do_add(self, value):
# No need for explicit lock - deques should be thread-safe:
# http://docs.python.org/2/library/collections.html#collections.deque
self.deque.append(value)
示例3: createCitation
# 需要导入模块: import collections [as 别名]
# 或者: from collections import html [as 别名]
def createCitation(self, multiCite = False):
"""Creates a citation string, using the same format as other WOS citations, for the [Record](./Record.html#metaknowledge.Record) by reading the relevant special tags (`'year'`, `'J9'`, `'volume'`, `'beginningPage'`, `'DOI'`) and using it to create a [Citation](./Citation.html#metaknowledge.citation.Citation) object.
# Parameters
_multiCite_ : `optional [bool]`
> Default `False`, if `True` a tuple of Citations is returned with each having a different one of the records authors as the author
# Returns
`Citation`
> A [Citation](./Citation.html#metaknowledge.citation.Citation) object containing a citation for the Record.
"""
#Need to put the import here to avoid circular import issues
from .citation import Citation
valsLst = []
if multiCite:
auths = []
for auth in self.get("authorsShort", []):
auths.append(auth.replace(',', ''))
else:
if self.get("authorsShort", False):
valsLst.append(self['authorsShort'][0].replace(',', ''))
if self.get("year", False):
valsLst.append(str(self.get('year')))
if self.get("j9", False):
valsLst.append(self.get('j9'))
elif self.get("title", False):
#No j9 means its probably book so using the books title/leaving blank
valsLst.append(self.get('title', ''))
if self.get("volume", False):
valsLst.append('V' + str(self.get('volume')))
if self.get("beginningPage", False):
valsLst.append('P' + str(self.get('beginningPage')))
if self.get("DOI", False):
valsLst.append('DOI ' + self.get('DOI'))
if multiCite and len(auths) > 0:
return(tuple((Citation(', '.join([a] + valsLst)) for a in auths)))
elif multiCite:
return Citation(', '.join(valsLst)),
else:
return Citation(', '.join(valsLst))