text stringlengths 0 828 |
|---|
return filename" |
4531,"def latex_quote(s): |
""""""Quote special characters for LaTeX. |
(Incomplete, currently only deals with underscores, dollar and hash.) |
"""""" |
special = {'_':r'\_', '$':r'\$', '#':r'\#'} |
s = str(s) |
for char,repl in special.items(): |
new = s.replace(char, repl) |
s = new[:] |
return s" |
4532,"def rec2latex(r, filename, empty=""""): |
""""""Export a recarray *r* to a LaTeX table in *filename*"""""" |
with open(filename, ""w"") as latex: |
latex.write(s_rec2latex(r, empty=empty)) |
return filename" |
4533,"def s_rec2latex(r, empty=""""): |
""""""Export a recarray *r* to a LaTeX table in a string"""""" |
latex = """" |
names = r.dtype.names |
def translate(x): |
if x is None or str(x).lower == ""none"": |
x = empty |
return latex_quote(x) |
latex += r""\begin{tabular}{%s}"" % ("""".join([""c""]*len(names)),) + ""\n"" # simple c columns |
latex += r""\hline""+""\n"" |
latex += "" & "".join([latex_quote(x) for x in names])+r""\\""+""\n"" |
latex += r""\hline""+""\n"" |
for data in r: |
latex += "" & "".join([translate(x) for x in data])+r""\\""+""\n"" |
latex += r""\hline""+""\n"" |
latex += r""\end{tabular}""+""\n"" |
return latex" |
4534,"def on(self, type): |
'''Decorator function''' |
def decorator(self, func): |
'''decorated functions should be written as class methods |
@on('join') |
def on_join(self, channel): |
print(""Joined channel %s"" % channel) |
''' |
self._handlers[type].append(func) |
return func |
return decorator" |
4535,"def tree_to_file(tree:'BubbleTree', outfile:str): |
""""""Compute the bubble representation of given power graph, |
and push it into given file."""""" |
with open(outfile, 'w') as fd: |
fd.write(tree_to_bubble(tree))" |
4536,"def lines_from_tree(tree, nodes_and_set:bool=False) -> iter: |
""""""Yield lines of bubble describing given BubbleTree"""""" |
NODE = 'NODE\t{}' |
INCL = 'IN\t{}\t{}' |
EDGE = 'EDGE\t{}\t{}\t1.0' |
SET = 'SET\t{}' |
if nodes_and_set: |
for node in tree.nodes(): |
yield NODE.format(node) |
for node in tree.powernodes(): |
yield SET.format(node) |
for node, includeds in tree.inclusions.items(): |
for included in includeds: |
yield INCL.format(included, node) |
for node, succs in tree.edges.items(): |
for succ in succs: |
yield EDGE.format(node, succ)" |
4537,"def to_python(self): |
""""""The string ``'True'`` (case insensitive) will be converted |
to ``True``, as will any positive integers. |
"""""" |
if isinstance(self.data, str): |
return self.data.strip().lower() == 'true' |
if isinstance(self.data, int): |
return self.data > 0 |
return bool(self.data)" |
4538,"def to_python(self): |
'''A :class:`datetime.datetime` object is returned.''' |
if self.data is None: |
return None |
# don't parse data that is already native |
if isinstance(self.data, datetime.datetime): |
return self.data |
elif self.use_int: |
return datetime.datetime.utcfromtimestamp(self.data / 1000) |
elif self.format is None: |
# parse as iso8601 |
return PySO8601.parse(self.data) |
else: |
return datetime.datetime.strptime(self.data, self.format)" |
4539,"def get_api_call_headers(app): |
"""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.