FAQ
Hi,

I created a class that's able to manipulate tabulated data. I want to be
able to dump the bulk of the data and other attributes as a tab-delimited
text. I have trouble saving/restoring type information in the file. For
example, some attributes are int, others may be float, etc. So I want to
store the data type as well as the data value themselves in a file. And I
don't think I want to use Pickle because I want it to be readily opened in
vi and be readable as a tab-delimited file and be able to import into Excel
as well.

What's the best way to achieve this? I was able to write string like
"attribute = int(value)" into a file. But how do I get the value back? I
want the "int(value)" string to be loaded into the program and be executable
so I can actually create the instance variable in the class.

Any help appreciated, thanks.

Timothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100618/5b5f7044/attachment-0001.html>

Search Discussions

  • Gabriel Genellina at Jun 22, 2010 at 12:11 pm
    En Fri, 18 Jun 2010 08:24:01 -0300, Timothy Wu <2huggie at gmail.com>
    escribi?:
    I created a class that's able to manipulate tabulated data. I want to be
    able to dump the bulk of the data and other attributes as a tab-delimited
    text. I have trouble saving/restoring type information in the file. For
    example, some attributes are int, others may be float, etc. So I want to
    store the data type as well as the data value themselves in a file. And I
    don't think I want to use Pickle because I want it to be readily opened
    in
    vi and be readable as a tab-delimited file and be able to import into
    Excel
    as well.

    What's the best way to achieve this? I was able to write string like
    "attribute = int(value)" into a file. But how do I get the value back? I
    want the "int(value)" string to be loaded into the program and be
    executable
    so I can actually create the instance variable in the class.
    Use the csv module to write your data in the RDB file format.
    The RDB format is fairly simple: first line contains the column names (tab
    separated), second line stores type information (tab separated), remaining
    lines contain actual data (also, tab separated).
    (You may use any format you want, but why reinvent it, and you may even
    find an existing RDB parser/writer in Python)

    --
    Gabriel Genellina

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 18, '10 at 11:24a
activeJun 22, '10 at 12:11p
posts2
users2
websitepython.org

2 users in discussion

Gabriel Genellina: 1 post Timothy Wu: 1 post

People

Translate

site design / logo © 2022 Grokbase