-
-
Save gcr/eeea119a7bdb0a4975df5804262508a3 to your computer and use it in GitHub Desktop.
Right-aligned python
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
import re | |
python_regex = re.compile(r"^(.*?)(\s*)$") | |
from IPython.core.magic import register_cell_magic, cell_magic, magics_class, Magics | |
@magics_class | |
class RightAlignMagics(Magics): | |
@cell_magic | |
def right_align(self, line, cell): | |
cell = "\n".join([ | |
python_regex.sub(r"\2\1", l) | |
for l in cell.split("\n") | |
]) | |
self.shell.run_cell(cell) | |
get_ipython().register_magics(RightAlignMagics) |
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
%%right_align | |
for x in xrange(50): | |
out = [] | |
if x % 7 == 0: | |
out.append("Fizz") | |
if x % 5 == 0: | |
out.append("Buzz") | |
if not out: | |
out = str(x) | |
print out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment