Ask Your Question
1

How can a cell output its own ID?

asked 2012-06-04 04:16:03 -0500

ooglyboogly gravatar image

updated 2015-01-13 14:26:15 -0500

FrédéricC gravatar image

I understand this works:

    C = sage.server.notebook.cell.Cell(0, '2+3', '5', None)
    C.id()

But I don't know understand how you can find that out for some arbitrary cell.

So far, the only way I know how is to use the interact decorator, and see what cell ids are used in the HTML.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2012-06-04 05:16:47 -0500

There must be a way to access this from Python. Meanwhile, if you click the "Edit" button, you'll see output like this:

{{{id=3|
Sq(4)**2
///
Sq(2,2)
}}}

I believe that id=3 means that the cell's id is 3. (The input is Sq(4)**2, and the output is Sq(2,2).)

edit flag offensive delete link more

Comments

Thanks. Don't know how I missed that. I guess I'll just make a new worksheet, and not delete cells so they're nice and orderly.

ooglyboogly gravatar imageooglyboogly ( 2012-06-04 07:39:50 -0500 )edit
1

answered 2012-06-04 08:26:15 -0500

Jason Grout gravatar image

User code can access the cell id using sagenb.notebook.interact.SAGE_CELL_ID. This is an unsupported variable, though, and may change in the future. It works for right now, though.

edit flag offensive delete link more

Comments

Unsupported in what sense? Is it different in the Flask notebook or in the Sage cell server? There must be some way to access this other than in the (very nonintuitive) interact module.

kcrisman gravatar imagekcrisman ( 2012-06-04 09:04:30 -0500 )edit

Great! Thanks.

ooglyboogly gravatar imageooglyboogly ( 2012-06-04 09:06:56 -0500 )edit

Unsupported in the sense that there is no guarantee it will be around in the future. It works in the Flask notebook. It does not work in the cell server (but I can tell you the "cell" id: it's going to be 1 :). And no, I think that's pretty much the only clean way to access the cell id.

Jason Grout gravatar imageJason Grout ( 2012-06-04 23:33:50 -0500 )edit

Then I put in a request that there be at least SOME way to do this in future versions of the notebook!

kcrisman gravatar imagekcrisman ( 2012-06-05 01:30:11 -0500 )edit

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

Stats

Asked: 2012-06-04 04:16:03 -0500

Seen: 136 times

Last updated: Jun 04 '12