database

Laurence Tratt tratt at dcs.kcl.ac.uk
Sun Jul 11 09:12:24 EDT 1999


In message <3787c551.1 at ganymede.datanet.hu>
          "dzsi" <granadam at mail.datanet.hu> wrote:

> i have a database (comma separated text), and i would like to get some
> data out of it based on some query. let's say there are seven fields,
> f1...f7, and i am searching for entries in f1, and want to display f1..f7 
> for the field that matches the query. how do i go about doing that?

Probably the first thing is to make / get a library that handles your
database types. By the sounds of things, you're using a CSV file so I'm
bound to reccomend my own CSV library <wink>. It's at version 0.17 and is
available from:

  http://eh.org/~laurie/comp/python/csv/

Then you can do fun things like:

    import CSV
    csv = CSV.CSV()
    csv.load(<file name>, 1)
    for entry in csv:
        if entry["f1"] <matches my criteria>:
            print entry    # prints f1 ... f7


Laurie
-- 
http://eh.org/~laurie/comp/python/




More information about the Python-list mailing list