Ask Your Question
0

getting blank cells in html.table

asked 2011-02-18 11:26:51 +0100

kcrisman gravatar image

I would like the following to give me a blank spot in a table in the notebook.

html.table([[1,None],[3,4]])

Unfortunately, it instead LaTeXs it to \mathrm{None}, which jsmath can't handle in any case. But I don't really want that behavior of latex() to change, but rather to figure out how to get the blank spot in the table without actually hacking the code of html.table (this is supposed to work on a server which is only updated once a semester).

edit retag flag offensive close merge delete

Comments

I built an EmptyCell class which changed _latex_ before realizing that even '' gives an empty cell.. is it too awkward to preprocess the table contents?

DSM gravatar imageDSM ( 2011-02-18 11:59:16 +0100 )edit

That's no problem at all. Are you saying that I could replace with an empty string? I didn't think about that.

kcrisman gravatar imagekcrisman ( 2011-02-18 12:00:41 +0100 )edit

Yes, this works. Can you make that an ANSWER so I can ACCEPT it? :-) Preferably with a nice example.

kcrisman gravatar imagekcrisman ( 2011-02-18 12:02:47 +0100 )edit

PS - I ran into trouble because I had tuples. So I had to do lists. But that was no problem either.

kcrisman gravatar imagekcrisman ( 2011-02-18 12:03:04 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-02-18 11:53:58 +0100

DSM gravatar image

updated 2011-02-18 12:07:11 +0100

html.table([[1, ''], [3,4]])

should do the trick, or, if like me you've gotten too object-oriented for your own good, you can do something like

class EmptyCell:
    def _latex_(self): return ''

Empty = EmptyCell()

html.table([[1, Empty], [3,4]])

which I'm only confessing to having written before even trying '' in the hopes that laughing at the above might help keep someone else from overthinking.

edit flag offensive delete link more

Comments

I had to process my table ahead of time to do this, replacing None with the empty string, but that worked. Next up - figuring out how to process a list of lists more easily than with a double loop and then finding the right sublist index to replace...

kcrisman gravatar imagekcrisman ( 2011-02-18 12:13:35 +0100 )edit

b = [[i if i != None else '' for i in l] for l in a] does it without indices, although it does have a double loop.

DSM gravatar imageDSM ( 2011-02-18 12:35:20 +0100 )edit

Yeah, I'm always hesitant to do double list comprehensions, but this would work great. I don't count a list comprehension as anywhere nearly as inelegant as a for loop with colon and indentation.

kcrisman gravatar imagekcrisman ( 2011-02-18 22:00:20 +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

Stats

Asked: 2011-02-18 11:26:51 +0100

Seen: 691 times

Last updated: Feb 18 '11