Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Flat file database

0 views
Skip to first unread message

Art Decco

unread,
Dec 23, 2003, 2:07:32 AM12/23/03
to
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.

Paul Rubin

unread,
Dec 23, 2003, 2:31:03 AM12/23/03
to
"Art Decco" <pleas...@email.com> 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?

Rony

unread,
Dec 23, 2003, 2:57:53 AM12/23/03
to
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

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/ bucodi_...@yahoo.fr (delete _no_spam)
/
| www.bucodi.com - My work
\ www.ifrance/karamusique -- My hobby
\_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


Art Decco

unread,
Dec 23, 2003, 3:56:46 AM12/23/03
to

"Paul Rubin" <http://phr...@NOSPAM.invalid> 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.

remco

unread,
Dec 23, 2003, 4:15:24 AM12/23/03
to

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

Paul Rubin

unread,
Dec 23, 2003, 4:18:47 AM12/23/03
to
"Art Decco" <pleas...@email.com> 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.

Miki Tebeka

unread,
Dec 23, 2003, 5:01:34 AM12/23/03
to
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

Aahz

unread,
Dec 23, 2003, 10:02:22 AM12/23/03
to
In article <UQRFb.115936$8y1.365571@attbi_s52>,

Art Decco <pleas...@email.com> 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 (aa...@pythoncraft.com) <*> 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.

Skip Montanaro

unread,
Dec 23, 2003, 11:45:40 AM12/23/03
to pytho...@python.org

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

John Roth

unread,
Dec 23, 2003, 2:05:46 PM12/23/03
to

"Art Decco" <pleas...@email.com> 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


mir nazim

unread,
Dec 24, 2003, 2:05:09 AM12/24/03
to
Rony <bucodi_...@ahoo.fr> wrote in message news:<bs8s99$oc5$1...@news-reader1.wanadoo.fr>...

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

0 new messages