[Tutor] New to Python and programming and need suggestion

alan.gauld@bt.com alan.gauld@bt.com
Mon, 8 Jan 2001 13:09:04 -0000

Its lunch time, so here's a reply.

> Hello, I'm new to programming and python (just bought Learn to
> Program Using Python by Alan Gauld, I'm on ch 14).  

First of all, thanks :-)
I hope you have seen the support web page:

I'm still adding errata as I go thru' the book myself.

> 1. There is a text file that I want to monitor for 
> certain key words, it is organized by date time msg.  
> The msg can be more than one word, and each date time 
> msg is on a seperate line. 

Up to here you should have enough from the book to 
tackle this bit.

> There are several
> computers that need to be monitored in this way.

This is more advanced and depends on things like 
whether you can see the files on the other computers 
as if they were local(ie via NFS or SMB etc) and 
what operating systems/networks are involved.

> 2. For the lines with those keywords I'd like to 
> have them uploaded onto a database running on a server.

That's not in the book so you will need to either 
buy a more advanced book or dig around on the 
Python web site. There is a lot of intro 
material there, it does depend a little bit on 
the database but for what you want there shouldn't 
be a problem. There is a generic API that will work
with most of the different database modules.
In turn Python modules exist for accessing 
most of the common databases.

Of course if the volumes are not going to be enormous 
you might find that simply creating a text file 
suffices... It's surprising how much can be done with simple textfiles if
you don't need to do sophisticated extracts.

> 3. I'd like people on the LAN to be able to look on a 
> intranet page and access the data on the database, 
> visually and if they need more detail with text.

Ok, This is the realm of CGI/ASP programming which is 
mentioned but not explained in the book. There are 
several guides/intros on the Python web site.

> maybe there is another way to monitor text files 
> remotly with a web page other than using a database 
> as an in-between?

Yes, you could simply have the CGI program read the 
original log files or an extracted text file you create
(as mentioned above). The great thing about this approach 
is that with a very little thought you can create a module 
of functions that can do the reading/writing and import it
for use in solving both both (1) and (3).

This will however, depend on your web server having access 
to the machines with the log files and arranging that the 
CGI programs themselves also have access - this usually 
involves your sys admin setting up an access control list 
or similar.

> having data sent to the database,
> and how to access the info with a web page.

Both topics have guides on the Python site, I'd try 
looking there first. Several of the more advanced 
Python books also have chapters on this.

> I'm assuming it can be done with python and some other tools, 

It can most certainly be done in Python.

I'd try reading a single log file first, and write the 
entries to a simple textbfile initially. Then try the 
CGI stuff because thats a fairly easy jump from what 
you know.

Once you have that working try accessing the other 
machines and merging the data. Either by running 
multiple copies of your first program - one per 
machine or by reading the files over the network.

[This shouldn't change the CGI web app at all.]

Finally, if performance is poor, explore the database 
topic, but you will need to learn a bit of SQL if you 
don't know it already. Thats in addition to how to 
access the data via Python....

I found the following article on databases useful 
as a starter (its linked to the Topic on the Python 


Other replies have been more specific but I'd go visit
the Topic Guides on the web site first then come back 
to the mail messages after reading them.

This list is always here for specific problems too.

Good luck,

Alan g.