[Tutor] Popen? or something else
Jacob S.
keridee at jayco.net
Thu Dec 23 02:55:27 CET 2004
Hi!
I just wondered why you included the time.localtime(time.time()) in the
defining of today.
Doesn't the default time.gmtime() work okay?
def gettoday():
import time
today = time.strftime('%Y%m%d%H')
return today
Jacob Schmidt
> Rumor has it that Ertl, John may have mentioned these words:
> >All,
> >
> >I hate to ask this but I have just installed 2.4 and I need to get some
info
> >from a subprocess (I think that is correct term).
> >
> >At the Linux command line if I input dtg I get back a string representing
a
> >date time group. How do I do this in Python? I would think Popen but I
> >just don't see it.
>
> It could, but there's also a better (IMHO), 'pythonic' way, something like
> this:
>
> def gettoday():
>
> import time
> today = time.strftime('%Y%m%d%H',time.localtime(time.time()))
> return (today)
>
> >$ dtg
> >2004122212
>
> If you wanted to use popen, it would look rather like this:
>
> import os
> dtg_s = os.popen("/path/to/dtg").readlines()[0]
>
> But this may use more system resources (spawning child shells & whatnot)
> than doing everything internally with the time module in Python.
>
> HTH,
> Roger "Merch" Merchberger
>
> --
> Roger "Merch" Merchberger | A new truth in advertising slogan
> SysAdmin, Iceberg Computers | for MicroSoft: "We're not the oxy...
> zmerch at 30below.com | ...in oxymoron!"
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list