Thanks Wim! That works perfectly. In fact my previous example code iterating over a TList was undoubtedly doing the exact same thing, testing a TKey pointer in a boolean context, and I simply didn't realize it. Rene Brun wrote: > To see the list of objects (with name and title) in the current > directory, do: > gDirectory->ls() My problem was that ls() writes to stdout, and so it's difficult to capture that information within a script. But now I see that I can call GetName and GetTitle on a TKey object. I thought I tried that earlier and it had failed, but now it's working! I also forgot that TKey is derived from TNamed, which provides these methods. Thanks to you both, Topher Cawlfield On Wednesday 30 June 2004 4:41 pm, WLavrijsen@lbl.gov wrote: > Topher, > > > How do I gracefully check for a null TObject pointer in pyroot? > > Use a boolean predicate, or if you want to turn it into a boolean value, > use > > the 'not not' trick. That is, from your example: > >>> this = tdir.Get("h400") > >>> print not not this > > 1 > > >>> that = tdir.Get("h401") > >>> print not not that > > 0 > > >>> if that: > > ... that.GetName() > ... > > >>> # <- nothing, as 'that' evaluates to > >>> False > > The assertion will be removed. You are quite right that an exception would > be far more appropriate. But that'll be for a later release. > > > How can I get the name (and title) of an object in a file without > > reading the whole thing into memory? > > Isn't that a general ROOT question? I'll have a look into it later, but I > need to warn you that I know next to nothing of using ROOT, so I may not > find an answer. > > HTH, > Wim
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET