Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Flat file database

Reply
Thread Tools

Flat file database

 
 
Art Decco
Guest
Posts: n/a
 
      12-23-2003
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.



 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      12-23-2003
"Art Decco" <(E-Mail Removed)> 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?
 
Reply With Quote
 
 
 
 
Rony
Guest
Posts: n/a
 
      12-23-2003
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

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/ http://www.velocityreviews.com/forums/(E-Mail Removed) (delete _no_spam)
/
| www.bucodi.com - My work
\ www.ifrance/karamusique -- My hobby
\_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


 
Reply With Quote
 
Art Decco
Guest
Posts: n/a
 
      12-23-2003

"Paul Rubin" <http://(E-Mail Removed)> 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.





 
Reply With Quote
 
remco
Guest
Posts: n/a
 
      12-23-2003
"Art Decco" <(E-Mail Removed)> 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
 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      12-23-2003
"Art Decco" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Miki Tebeka
Guest
Posts: n/a
 
      12-23-2003
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
 
Reply With Quote
 
Aahz
Guest
Posts: n/a
 
      12-23-2003
In article <UQRFb.115936$8y1.365571@attbi_s52>,
Art Decco <(E-Mail Removed)> 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 ((E-Mail Removed)) <*> 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.
 
Reply With Quote
 
Skip Montanaro
Guest
Posts: n/a
 
      12-23-2003

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

 
Reply With Quote
 
John Roth
Guest
Posts: n/a
 
      12-23-2003

"Art Decco" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
flat file vs sql database Inspector ASP .Net 10 11-25-2005 03:37 PM
java with ISAM , flat-file database with multiple keys Mohammad S Khan Java 3 08-31-2004 12:59 PM
small, fast and cross-platform flat-file database for python mir nazim Python 7 11-24-2003 05:23 PM



Advertisments