Ask Your Question

Custom Input Transformation

asked 2015-10-28 18:58:34 +0200

jediknight219 gravatar image

updated 2015-10-28 19:23:44 +0200

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 19:36:12 +0200

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 18:58:34 +0200

Seen: 465 times

Last updated: Oct 28 '15