Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter: Line magic function not found

I've got a persistent error:

%%writefile csvmagic.py
import pandas as pd
from io import StringIO

def csv(line, cell):
    sio = StringIO(cell)
    return pd.read_csv(sio)

def load_ipython_extension(ipython):
    """This function is called when the extension is
    loaded. It accepts an IPython InteractiveShell
    instance. We can register the magic with the
    `register_magic_function` method of the shell
    instance."""
    ipython.register_magic_function(csv, 'cell')

Overwriting csvmagic.py



%reload_ext csvmagic
%%csv
col1,col2,col3
0,1,2
3,4,5
7,8,9

UsageError: Line magic function `%%csv` not found.

"Line magic" does not look quite right to me, but I can't figure it out.

The source is here

like image 811
Alexey Orlov Avatar asked May 11 '26 21:05

Alexey Orlov


1 Answers

Afaik, you must put cell magics at the beginning of a cell. However, %%csv is inside of your code block. Make sure that the section starting with %%csv is in a cell of its own. Otherwise, what is supposed to be a cell magic will be interpreted as a line magic.

like image 171
Roland Weber Avatar answered May 14 '26 12:05

Roland Weber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!