[Numpy-discussion] RecArray.tolist() suggestion

Francesc Alted falted at pytables.org
Thu Jul 15 11:21:10 CDT 2004


A Dijous 15 Juliol 2004 19:37, Perry Greenfield va escriure:
> formats that would like to map field name exactly. Well certainly
> one can still use the attribute approach and not support all field
> names (or column, or col...) it does introduce another glitch in
> the user interface when it works only for a subset of legal names.

Yep. I forgot that issue. My particular workaround on that was to provide an
optional trMap dictionary during Table (in our case, RecArray) creation time
to map those original names that are not valid python names by valid ones. 

That would read something like:

>>> r=records.array([(1,"as")], "1i4,1a2",
                    names=["c 1", "c2"], trMap={"c1": "c 1"})

that would indicate that the "c 1" column which is not a valid python name
(it has an space in the middle) can be accessed by using "c1" string, which
is a valid python id. That way, r.cols.c1 would access column "c 1".

And although I must admit that this solution is not very elegant, it allows
to cope with those situations where the columns are not valid python names.

-- 
Francesc Alted





More information about the Numpy-discussion mailing list