parsing a date string

2005-03-06 Thread MikeyG
Hi,
I have a date string in the ctime() format ('Sat Mar  5 10:38:07 2005') 
and I want to know how long ago that was in whole days.

So far I have:
import time
import datetime
age = 
(datetime.date.fromtimestamp(time.mktime(time.strptime(date.strip( - 
datetime.date.today()).days

Which is an absurd number of function calls and is possibly not even 
correct (something in the docs about mktime() taking localtime whereas 
my string is in UTC)

Any suggestions?
Thanks
MikeG
--
http://mail.python.org/mailman/listinfo/python-list


Re: python -i (interactive environment)

2005-03-06 Thread MikeyG
Joe wrote:
When you run "python -i scriptname.py" after the script completes you left 
at the interactive command prompt.

Is there a way to have this occur from a running program?
In other words can I just run scriptname.py (NOT python -i scriptname.py) 
and inside of scriptname.py I decide that I want to fall back to the 
interactive prompt?

I've searched and so far the only thing I've come up with is to use pdb, but 
that is not exactly the same as the interactive prompt.

Is there any way to do it that I have missed?
Thanks. 


Yes you can set the PYTHONINSPECT environment variable to something 
other than an empty string from within your program.

MikeG
--
http://mail.python.org/mailman/listinfo/python-list


Re: Variable Variable

2005-03-20 Thread MikeyG
Premshree Pillai wrote:
On Sat, 19 Mar 2005 04:35:47 -0500, Leif K-Brooks <[EMAIL PROTECTED]> wrote:
Tanteauguri wrote:
Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc:
   i = anyclass()
a.shutdown()
b.update()
Use a dictionary:
stuff = {}
pc = ['a', 'b', 'c']

I think what he wants to do is basically hold object names in a tuple
list, and then call the methods on those objects (while iterating or
whatever).

for i in pc:
stuff[i] = anyclass()
stuff['a'].shutdown()
stuff['b'].update()
--
http://mail.python.org/mailman/listinfo/python-list

Try this:
pc=["a","b","c"]
for i in pc:
vars()[i] = anyclass()
a.shutdown()
b.update()
MikeG
--
http://mail.python.org/mailman/listinfo/python-list