This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By example, I wanted to replace all inline math $...$ with \( ... \). So I had to match the (escaped) dollar sign \$ then put the text inbetween in a group (this is achieved by the parentheses). The brackets, in usual regex style, form a category of symbols. In this case every symbol but the dollar sign in order to simulate non-greedy matching. This is like using .+? in normal regular expressions. So the search pattern is: | |
\$([^\$]+)\$ | |
The group given by the parentheses can be referred to in the replacement by \1, so the replacement text is: | |
\\( \1 \\) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_argument(arg, new_type, default=None): | |
""" | |
Convert an argument to a new type unless it is `None`. | |
""" | |
return default if arg is None else new_type(arg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MetaBase(type): | |
""" | |
Metaclass for MutableBase. | |
This metaclass is one of two possible solutions to having a per-class | |
mutable class attribute. The per-class aspect is tricky because the | |
attribute is a mutable object. It is thus shared among MutableBase and all | |
its subclasses. | |
Shared state of the mutable class attribute is avoided with this metaclass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __getattr__(self, attribute): | |
""" | |
Defer any attribute access that was unsuccessful to a compound class. | |
Introduce a safeguard, for example, when unpickling this class, by raising an AttributeError. | |
""" | |
if "compound" in self.__dict__: | |
self.compound.__getattribute__(attribute) | |
raise AttributeError("'{0}' object has no attribute '{1}'".format(self.__class__.__name__, attribute)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProgressPrinter(object): | |
""" | |
Write a recurring message to a stream on the same line. | |
Warning | |
------- | |
Only works properly if the message fits on a single line for the given | |
stream. | |
""" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "simple_tf_gene_network" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |
OlderNewer