Ask Your Question
1

How can a cell output its own ID?

asked 12 years ago

ooglyboogly gravatar image

updated 10 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 12 years ago

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.

Preview: (hide)
link

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 ( 12 years ago )

Great! Thanks.

ooglyboogly gravatar imageooglyboogly ( 12 years ago )

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 ( 12 years ago )

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 ( 12 years ago )
1

answered 12 years ago

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).)

Preview: (hide)
link

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 ( 12 years ago )

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: 12 years ago

Seen: 488 times

Last updated: Jun 04 '12