"pickle" vs. f.write()

2005-01-26 Thread Johan Kohler
Hi,
I have a class with attributes that are string, integer and list.  eg.
class person:
name =""
age = 0
friends=[]
comment=""
me = person()
I want to save a whole bunch of instances to a file, a classic "records"  
file I/O.

To write the file, I can do f.write(str([me.name, me.age, me.friends,  
me.comment]) + "\n"

This works nicely for writing, but when reading, I cannot convert the  
string easily to a list:
list(f.readline()) is not the same as [me.name, me.age, me.friends,  
me.comment]

I was wondering whether pickle might make this easier - an example would  
be much appreciated.

Otherwise, what is the best "Python" way to write and read this data  
structure?

Thanks in advance...
Johan
__
Yes, I do feel stupid asking this, but time's-a-runnin' out..
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Please find our disclaimer at http://www.ukzn.ac.za/disclaimer

<<<>>>
--
http://mail.python.org/mailman/listinfo/python-list


Re: "pickle" vs. f.write()

2005-01-26 Thread Johan Kohler
Thanks... works like a charm :-)
On Wed, 26 Jan 2005 12:55:38 +0100, Peter Maas <[EMAIL PROTECTED]> wrote:
Johan Kohler schrieb:
class person:
name =""
age = 0
friends=[]
comment=""""""
 me = person()
 Otherwise, what is the best "Python" way to write and read this data   
structure?
import pickle
class person:
 name =""
 age = 0
 friends=[]
 comment=""""""
me = person()
# store
pf = file('/tmp/pickletest', 'w')
pickle.dump(me, pf)
pf.close()
# load
pf = file('/tmp/pickletest', 'r')
me2 = pickle.load(pf)
pf.close()
This is sequential access. If you want to have random access, look
for shelve.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Please find our disclaimer at http://www.ukzn.ac.za/disclaimer

<<<>>>
--
http://mail.python.org/mailman/listinfo/python-list


Speeding up CGIHTTPServer

2005-03-06 Thread Johan Kohler
Hi,
I'm using CGIHTTPServer (via its test() method) to test some CGI on my
Windoze 98 box.  I find that the execution is very slow.  Is there
anything I can do to make sure I'm getting the best performance out of
CGIHTTPServer?

Thanks in advance,
Johan


Please find our disclaimer at http://www.ukzn.ac.za/disclaimer

<<<>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Speeding up CGIHTTPServer (Tim Roberts)

2005-03-08 Thread Johan Kohler
On Tue,  8 Mar 2005 10:25:46 +0100 (CET), <[EMAIL PROTECTED]>  
wrote:

I'm using CGIHTTPServer (via its test() method) to test some CGI on my
Windoze 98 box.  I find that the execution is very slow.  Is there
anything I can do to make sure I'm getting the best performance out of
CGIHTTPServer?

Compared to what, and on what hardware?

CGI is not a rip-roaring performance demon on any platform, but
CGIHTTPServer is designed to be convenient more than fast.  It isn't  
going
to do as well as a native server.
The key question you need ask is this: is it fast enough?  If you're  
doing
a web page for internal use that is only going to get a hundred hits a  
day,
who cares if each page takes 5 seconds to render?  If you're doing 10,000
hits a day, you need to choose something other than Windows 98.
Fair enough.  Pretend my question said "compared to apache, but also to  
CGIHTTPServer on linux".  The Windows box has modest specs Celeron 2.8GHz,  
256MB, but it takes 30-60s render pages.  I was using it to test my cgi  
locally, ie. no network, one user

Windows bashing is fun :-) but unfortunately I don't think that is the  
issue here.  The answer I was looking for was something like - "yes,  
change config file so-and-so in such-and-such a way" or simply "no."

If there is no way to improve performance, could anyone tell my _why_ it's  
running so slowly?  Presumably spawning a process takes some time.  The  
code I'm running as CGI is not hectic at all.

Thanks in advance,
Johan

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Please find our disclaimer at http://www.ukzn.ac.za/disclaimer

<<<>>>
--
http://mail.python.org/mailman/listinfo/python-list