Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%q cell magic #37

Open
Matoran opened this issue Oct 17, 2024 · 0 comments
Open

%q cell magic #37

Matoran opened this issue Oct 17, 2024 · 0 comments

Comments

@Matoran
Copy link

Matoran commented Oct 17, 2024

Is your feature request related to a problem? Please describe.
Hi, no problem related. Pyq had the functionality of both cell and line magics which was useful to explore tables.

Describe the solution you'd like
Adding the functionality

Describe alternatives you've considered
I changed locally my nbextension.py file to support it.

def q_line(code):
    return q("", code + "\n")


def load_ipython_extension(ipython):
    ipython.register_magic_function(q, "cell")
    ipython.register_magic_function(q_line, "line", "q")

Second version, more clean but changes q function:
if code is None, it means line magic. We need to patch code and instructions to execute correctly.

def q(instructions,code=None):
    if code == None:
        code = instructions + "\n"
        instructions = ""
        ...


def load_ipython_extension(ipython):
    ipython.register_magic_function(q, "both")

Additional resource
https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.interactiveshell.html#IPython.core.interactiveshell.InteractiveShell.register_magic_function
https://github.com/KxSystems/pyq/blob/8c31f19e6ee8970d5b4146c5593cb1ed174e1385/src/pyq/magic.py#L47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant