本文整理匯總了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))