Created
November 12, 2013 09:07
-
-
Save vietjtnguyen/7427816 to your computer and use it in GitHub Desktop.
Python script to do in place calculations while in vim. Inspired by https://github.com/arecarn/crunch.
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
#!/usr/bin/python | |
#import numpy as np | |
#import pandas as pd | |
#import scipy as sp | |
#import scipy.ndimage as nd | |
#import scipy.signal as sg | |
#import itertools, pickle, random, os | |
from math import * | |
import sys | |
for line in sys.stdin.readlines(): | |
line = line[:line.rfind('#')] | |
try: | |
code_object = compile(line, '', 'eval') | |
output = '# = {:}'.format(str(eval(code_object))) | |
except SyntaxError as e: | |
code_object = compile(line, '', 'exec') | |
exec code_object | |
output = '' | |
print('{:}{:}'.format(str(line).strip(), output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python script to do in place calculations while in vim. Inspired by https://github.com/arecarn/crunch.
For example, say you have this block of text in vim:
If you have your cursor somewhere in the second paragraph you can evaluate it with
{V}:!./pycalc.py
(assuming pycalc.py is in the working directory). What you get after is the following: