Flat file database

Discussion in 'Python' started by Art Decco, Dec 23, 2003.

  1. Art Decco

    Art Decco Guest

    Is there any Python module designed to simplify the use of a plain text file
    as a flat file database?

    I realize that's a bit vague, but I'm just wondering about the best approach
    for creating a little database-backed CGI app using Python on a server with
    no real database available. The server belongs to the ISP, and I don't get
    to install "real" software, but they do have a cgi-bin directory for me, and
    they do have a relatively recent Python, so I've got Python cgi apps working
    via "#!/usr/local/bin/python". I can get the apps to write and read plain
    text files right in the cgi-bin directory, too, so I can use that as a
    simple, flat file database.

    Now, the question is, do I write all the database
    access/update/sort/search/etc. features myself, or is there some Python
    module that has implemented some useful functions that I should build on.
    I'm pretty new to Python (though not to programming), so if there's a
    standard way most skilled Pythonistas would approach something like this,
    I'd like to know what it is. And if there's something that goes beyond flat
    file and has some relational support as well, all the better.

    Thanks for any suggestions.
     
    Art Decco, Dec 23, 2003
    #1
    1. Advertising

  2. Art Decco

    Paul Rubin Guest

    "Art Decco" <> writes:
    > I realize that's a bit vague, but I'm just wondering about the best approach
    > for creating a little database-backed CGI app using Python on a server with
    > no real database available. The server belongs to the ISP, and I don't get
    > to install "real" software, but they do have a cgi-bin directory for me, and
    > they do have a relatively recent Python, so I've got Python cgi apps working
    > via "#!/usr/local/bin/python". I can get the apps to write and read plain
    > text files right in the cgi-bin directory, too, so I can use that as a
    > simple, flat file database.


    Most web hosts offer you access to a database, typically MySQL. Use
    that if you can. Implementing what you're asking is harder than it
    sounds. What happens if two people connect to your application both
    try to update the database at the same time?
     
    Paul Rubin, Dec 23, 2003
    #2
    1. Advertising

  3. Art Decco

    Rony Guest

    Art Decco wrote on Tue, 23 Dec 2003 07:07:32 GMT in : <UQRFb.115936$8y1.365571@attbi_s52>

    > Is there any Python module designed to simplify the use of a plain text file
    > as a flat file database?
    >
    > ...


    You could have a look at kirbybase

    Rony
    --
    Rony

    /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
    / (delete _no_spam)
    /
    | www.bucodi.com - My work
    \ www.ifrance/karamusique -- My hobby
    \_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
     
    Rony, Dec 23, 2003
    #3
  4. Art Decco

    Art Decco Guest

    "Paul Rubin" <http://> wrote >
    > Most web hosts offer you access to a database, typically MySQL. Use
    > that if you can. Implementing what you're asking is harder than it
    > sounds. What happens if two people connect to your application both
    > try to update the database at the same time?


    Actually, I've done it before in Perl. Perl makes multithreaded access to
    files pretty easy (on Unix).

    But this case is much easier. It's just for personal use. I'll probably be
    the only user, so a minimal backup is all I need to do for data integrity. I
    don't need record locking or even file locking. Of course that may make my
    case so unusual that no module exists, but it's worth asking before I once
    again reinvent the concept of a simple flat-file database as I, and most
    other programmers, have done so many times before.

    And I don't think MySQL is available without switching to a more expensive
    type of account. This application, essentially a fancy Christmas card list,
    just isn't worth all that trouble, but it would be nice if someone knows of
    a Python module that makes simple text file management a little easier.
     
    Art Decco, Dec 23, 2003
    #4
  5. Art Decco

    remco Guest

    "Art Decco" <> wrote:
    >
    >Is there any Python module designed to simplify the use of a plain text file
    >as a flat file database?
    >
    >I realize that's a bit vague, but I'm just wondering about the best approach
    >for creating a little database-backed CGI app using Python on a server with
    >no real database available. The server belongs to the ISP, and I don't get
    >to install "real" software, but they do have a cgi-bin directory for me, and
    >they do have a relatively recent Python, so I've got Python cgi apps working
    >via "#!/usr/local/bin/python". I can get the apps to write and read plain
    >text files right in the cgi-bin directory, too, so I can use that as a
    >simple, flat file database.
    >
    >Now, the question is, do I write all the database
    >access/update/sort/search/etc. features myself, or is there some Python
    >module that has implemented some useful functions that I should build on.
    >I'm pretty new to Python (though not to programming), so if there's a
    >standard way most skilled Pythonistas would approach something like this,
    >I'd like to know what it is. And if there's something that goes beyond flat
    >file and has some relational support as well, all the better.
    >
    >Thanks for any suggestions.
    >


    You could see if the Berkley db is available (bsddb module).
    The Berkley DB is normally builtin. It behaves like a dictionary, and is
    therefore
    simple and straightforward.

    Cheers,
    Remco Boerma
     
    remco, Dec 23, 2003
    #5
  6. Art Decco

    Paul Rubin Guest

    "Art Decco" <> writes:
    > And I don't think MySQL is available without switching to a more expensive
    > type of account. This application, essentially a fancy Christmas card list,
    > just isn't worth all that trouble, but it would be nice if someone knows of
    > a Python module that makes simple text file management a little easier.


    I don't understand then why you want such a module. If there's just a
    few dozen lines in the file, then read it into memory, change whatever
    you want, and write it out again.

    Personally for these kinds of database applications though, I usually
    use the anydbm module.
     
    Paul Rubin, Dec 23, 2003
    #6
  7. Art Decco

    Miki Tebeka Guest

    Hello Art,

    > Is there any Python module designed to simplify the use of a plain text file
    > as a flat file database?

    You might want to take a loot at metakit (http://www.equi4.com/metakit/python.html)

    HTH.
    Miki
     
    Miki Tebeka, Dec 23, 2003
    #7
  8. Art Decco

    Aahz Guest

    In article <UQRFb.115936$8y1.365571@attbi_s52>,
    Art Decco <> wrote:
    >
    >Is there any Python module designed to simplify the use of a plain text file
    >as a flat file database?


    Why do you want plain-text? I've got a half-assed module for searching
    a formatted plain-text database, but the whole point of it is that it
    does *not* have a write/update interface -- it's designed to be
    maintained with a text editor. For your purpose, why not just pickle a
    Python dict?
    --
    Aahz () <*> http://www.pythoncraft.com/

    Weinberg's Second Law: If builders built buildings the way programmers wrote
    programs, then the first woodpecker that came along would destroy civilization.
     
    Aahz, Dec 23, 2003
    #8
  9. Art> Is there any Python module designed to simplify the use of a plain
    Art> text file as a flat file database?

    Several others have mentioned various possibilities. If Python
    2.3 is available to you, you might consider the csv module. You can edit
    the files with Excel or another spreadsheet. In your code, you can use the
    csv.DictReader class to pull out the fields of interest:

    # just off the top of my head!
    def select(where, csvfile):
    "return rows from csvfile which overlap with dictionary 'where'."

    results = []
    for row in csv.DictReader(csvfile):
    if matches(where, row):
    results.append(row)
    return results

    Coding of the matches function is left as an exercise for the reader. <wink>

    Skip
     
    Skip Montanaro, Dec 23, 2003
    #9
  10. Art Decco

    John Roth Guest

    "Art Decco" <> wrote in message
    news:UQRFb.115936$8y1.365571@attbi_s52...
    > Is there any Python module designed to simplify the use of a plain text

    file
    > as a flat file database?
    >
    > I realize that's a bit vague, but I'm just wondering about the best

    approach
    > for creating a little database-backed CGI app using Python on a server

    with
    > no real database available. The server belongs to the ISP, and I don't get
    > to install "real" software, but they do have a cgi-bin directory for me,

    and
    > they do have a relatively recent Python, so I've got Python cgi apps

    working
    > via "#!/usr/local/bin/python". I can get the apps to write and read plain
    > text files right in the cgi-bin directory, too, so I can use that as a
    > simple, flat file database.


    Python 2.3 has a CSV module to read and write files in Comma
    Separated Variable format. This might do the job for you if you can
    stand to read the file and convert it to in-storage objects, and then write
    out a new version if it's updated.

    Another possibility along the same lines is the pickle module: that can
    put out an entire tree of objects, and then read them back in. That's
    been around for a while. That will be availible for any release of
    Python that your ISP is likely to have installed.

    As far as relational support, I'd suggest hitting Google to see what
    you can turn up.

    John Roth
     
    John Roth, Dec 23, 2003
    #10
  11. Art Decco

    mir nazim Guest

    Rony <> wrote in message news:<bs8s99$oc5$>...
    > Art Decco wrote on Tue, 23 Dec 2003 07:07:32 GMT in : <UQRFb.115936$8y1.365571@attbi_s52>
    >
    > > Is there any Python module designed to simplify the use of a plain text file
    > > as a flat file database?
    > >
    > > ...

    >
    > You could have a look at kirbybase
    >
    > Rony
    > --
    > Rony
    >
    > /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
    > / (delete _no_spam)
    > /
    > | www.bucodi.com - My work
    > \ www.ifrance/karamusique -- My hobby
    > \_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/




    yeh, Ront is right, it is a plain simple python program (one file). if
    u can do without sql, it may be helpful.
    get it here
    http://www.netpromi.com/kirbase
     
    mir nazim, Dec 24, 2003
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Inspector

    flat file vs sql database

    Inspector, Nov 23, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    1,015
    Inspector
    Nov 25, 2005
  2. Mohammad S Khan
    Replies:
    3
    Views:
    8,724
    Chris Uppal
    Aug 31, 2004
  3. mir nazim
    Replies:
    7
    Views:
    555
    Brian Kelley
    Nov 24, 2003
  4. John Benson
    Replies:
    0
    Views:
    306
    John Benson
    Nov 22, 2003
  5. Tim Churches
    Replies:
    2
    Views:
    419
    mir nazim
    Dec 8, 2003
Loading...

Share This Page