Hello,

Rainy sill at optonline.net
Sun Jul 22 02:22:52 EDT 2001


On Sun, 22 Jul 2001 03:10:37 +1000, Lee Nutter <leenutter at australia.edu> wrote:
> Hello!,
> 
> I have only been subscribed to this list three days, this is my first 
> message :)
> 
> Anyway, im just messing here, not doing anything in particular, just 
> playing with what I have learned in an attempt to learn the language.
> 
> Anyway, I decided to make a module that handles errors for me. Its not 
> likely my projects are going to be complex enough for me to need it for 
> a while, but I thought it would be fun none the less [and a learning 
> experience, of course :) ]
> 
> In the Python docs, it mentions that open("file", "a") allows you to use 
> write() to append strings at the bottom of a file. But I wanted my error 
> handler to do it the other way round, add the newest entries to the top. 
> [I've already been told this is wrong, and it should be the other way 
> round anyway, but I want to be different. And anyhow, im only messing. :) ]
> 
> I came up with this code after a little messing around :
> 
> 
> def LogError(msg):
>    err = open("./error.log", "r")
>    old = err.readlines()
>    err.close()
>    err = open("./error.log", "w")
>    wri = msg
>    i = 0
>    p = len(old)
>    while i < p:
>      wri = wri + old[i]
>      i = i + 1
>    err.write(wri)
>    err.close
> 

How about 
err=open(logfile, 'a') # for appending
err.write(msg)

> 
> This works, but I have been told it will be slow if error.log gets big, 
> Is there another way to do this?
> 
> Anyway, Thanks for any replies!
> 
> Kind Regards,
> 
> 
> Lee Nutter
> 
> 


-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: http://silmarill.org/cymbaline



More information about the Python-list mailing list