Re: Linux shell to python

Discussion in 'Python' started by Philipp Hagemeister, Jul 30, 2012.

  1. On 07/30/2012 09:05 AM, Vikas Kumar Choudhary wrote:
    > `lspci | grep Q | grep "$isp_str1" | grep "$isp_str2" | cut -c1-7'


    The rough Python equivalent would be

    import subprocess
    [ l.partition(' ')[0] # or l[:7], if you want to copy it verbatim
    for l in subprocess.check_output(['lspci']).splitlines()
    if 'Q' in l and isp_str1 in l and isp_str2 in l
    ]

    You can also just paste the whole pipeline with the shell=True
    parameter. That's not recommended though, and it's hard to correctly
    quote strings.

    - Philipp


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.12 (GNU/Linux)

    iEYEAREKAAYFAlAWY3wACgkQ9eq1gvr7CFykBQCeNC7F/jZP8xOWwLvKGruTOhpy
    sWYAoI44zaEeM5qKwX2tdH3ZuuFpgrwb
    =8rax
    -----END PGP SIGNATURE-----
     
    Philipp Hagemeister, Jul 30, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,771
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    611
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,106
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    879
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. edwithad

    Bash shell to Python shell?

    edwithad, Sep 28, 2009, in forum: Python
    Replies:
    4
    Views:
    1,765
Loading...

Share This Page