Ask Your Question

Custom Input Transformation

asked 2015-10-28 12:58:34 -0500

jediknight219 gravatar image

updated 2015-10-28 13:23:44 -0500

Greetings. I am trying to emulate the << >> functionality of OCaml in python on For instance, if I type:


I want it to call default_parser("stuff"). I have it working if << and >> are on the same line, but I want it to be able to span multiple lines. Here's my code:

from IPython.core.inputtransformer import (StatelessInputTransformer)

def quotations(line):
    if line is not None:
        line = line.replace("<<", 'default_parser("""')
        line = line.replace(">>", '""")')
    return line

ip = get_ipython()

It can't handle this:


It replaces the << in the first line just fine, but apparently once it goes into triple quote mode, it stops calling my transformation function.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-10-28 13:36:12 -0500

jediknight219 gravatar image

Figured it out. Replaced logical_line_transforms with physical_line_transforms.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-10-28 12:58:34 -0500

Seen: 57 times

Last updated: Oct 28 '15