[Tutor] Popen? or something else

Ertl, John john.ertl at fnmoc.navy.mil
Wed Dec 22 20:10:13 CET 2004


I have been doing it the Pythonic way (that is why I have no idea about how
Popen works) but I need to make sure (the systems guys called me on it)  I
use the same dtg as everyone else...it is possible (has not happened yet in
20 years) it could be set to something else.

Is the example you gave using the new 2.4 Popen?  It looks like the older
popen.  I can get the older popen to work but not Popen.  

Thanks again.

John Ertl 

-----Original Message-----
From: Roger Merchberger [mailto:zmerch at 30below.com]
Sent: Wednesday, December 22, 2004 10:25
To: tutor at python.org
Subject: Re: [Tutor] Popen? or something else

Rumor has it that Ertl, John may have mentioned these words:
>I hate to ask this but I have just installed 2.4 and I need to get some
>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

def gettoday():

  import time
  today = time.strftime('%Y%m%d%H',time.localtime(time.time()))
  return (today)

>$ dtg

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.

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

More information about the Tutor mailing list