Ask Your Question
1

How can a cell output its own ID?

asked 2012-06-04 11:16:03 +0100

ooglyboogly gravatar image

updated 2015-01-13 21:26:15 +0100

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 15:26:15 +0100

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 16:04:30 +0100 )edit

Great! Thanks.

ooglyboogly gravatar imageooglyboogly ( 2012-06-04 16:06:56 +0100 )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-05 06:33:50 +0100 )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 08:30:11 +0100 )edit
1

answered 2012-06-04 12:16:47 +0100

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 14:39:50 +0100 )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 11:16:03 +0100

Seen: 461 times

Last updated: Jun 04 '12