Python collections.html() Examples
The following are 3
code examples of collections.html().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
collections
, or try the search function
.
Example #1
Source File: mkRecord.py From metaknowledge with GNU General Public License v2.0 | 6 votes |
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
Example #2
Source File: histogram.py From appmetrics with Apache License 2.0 | 5 votes |
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)
Example #3
Source File: mkRecord.py From metaknowledge with GNU General Public License v2.0 | 4 votes |
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))