A Tuesday 20 May 2008, Pan, Jianfu (GSFC-610.2)[ADNET] escrigué:
> Hi,
>
>
>
> I understand that a table structure can be created in pytables with
> named columns.  I'd like to have a way to create the table
> dynamically. That is, my number of columns and column names and types
> are all variables.  Does any one know if this is possible?  Thanks
> for your time.

Yes.  From the docstrings of the `createTable` method:

[snip]
    `description`
        This is an object that describes the table, i.e. how many
        columns it has, their names, types, shapes, etc.  It can be
        any of the following:

        A user-defined class
            This should inherit from the `IsDescription` class where
            table fields are specified.

        A dictionary
            For example, when you do not know beforehand which
            structure your table will have).

        A `Description` instance
            You can use the ``description`` attribute of another
            table to create a new one with the same structure.

        A NumPy (record) array
            You can use a NumPy array, whether nested or not, and
            its field structure will be reflected in the new `Table`
            object.  Moreover, if the array has actual data it will
            be injected into the newly created table...
[snip]

So, you can use basically two methods: a dictionary or a NumPy recarray. 
Use whatever is easier for you.  You can find an example with a NumPy 
recarray here:

http://article.gmane.org/gmane.comp.python.pytables.user/881

Hope that helps,

-- 
Francesc Alted

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to