[Tutor] Grabbing Information from txt files

Michael Stover m_stover43812us at yahoo.com
Sat Nov 13 03:43:05 CET 2010


My apologies for my last email, admittedly I was more tired that I thought as 
after re-reading it and the emails coming in, I found that I did not provided 
"proper" information.

1. I have a script that is detecting multiple various bits of information of a 
video file using MediaInfo and putting that information into a txt file with the 
format of:
(Example:)
num_vid_track=?
num_aud_track=?
num_sub_track=?

Granted that is only part of the information being obtained but it's all in the 
same format.
I have been trying multiple ways of grabbing this information for re-use, 
including using this snippet, suggested to me by fellow users of the #python irc 
channel..

import shlex as shlex_
from subprocess import Popen, PIPE

def shell(args, input=None, stdout=PIPE, stderr=PIPE, shlex=False, **kwargs):
    """Gets the output of a command run in a subprocess.
    
    Arguments:
        args:   A sequence of strings, or a single string if shlex=True.
        input:  A string to be written to the process's stdin.
        Any extra keyword arguments are forwarded to Popen.
    
    Returns:
        A tuple of (stdout, stderr)
        
    >>> shell('basename /a/hello', shlex=True)
    ('hello\n','')
    """
    if shlex:
        args = shlex_.split(args)
    stdin = PIPE if input is not None else None
    p = Popen(args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
    return p.communicate(input=input)

Then using a command line similar to:
p = subprocess.Popen(['foo', 'bar'], stdout=subprocess.PIPE); stdout, _ = 
p.communicate()

Where 'foo','bar' obviously is the program I am calling with its arguements. The 
only issue is, I can barely understand the documentation I kept getting pointed 
to for retrieving the information captured from stdout. Which is why I went with 
another friends suggestion of outputting all of the information to a text file. 
Sorry if this seems to have veered off course, but which method would be more 
recommended to implement? So far I have been able to write a different python 
script for a general conversion of videos from multiple different formats to a 
single format my xbox 360 can read (with or without is optional media update).

Again sorry for my previous email, and thank you in advance for the assistance 
and suggestions,
Mike



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101112/fbb2b3e3/attachment.html>


More information about the Tutor mailing list