Receiving Output from os.system command

K-Dawg kdawg44 at
Mon Jan 19 20:14:35 CET 2009

I am really new to python and am trying to learn it to do some projects.  I
wanted to perform a simple task and am having some trouble with it.  I run
linux in a vm on a windows laptop for work.  I have my laptop screen and an
external monitor.  I move my Ubuntu VM back and forth depending on what I am
working on so I wanted to write a little python script that changed the
resolutions depending on what the current resolution is.

I have:

#! /usr/bin/python

import sys
import os
import re

re_currentResolution = re.compile(r'current \d{4}\sx\s\d{3,4}')
xrandr_output = os.popen('xrandr').readlines()
currentRes =

I just want to grab the xrandr output as a string and parse it with the
regex.  This will give me a string with the current resolution, for instance
"current 1024 x 768".  I would then split that up and call back to the
os.system('xrandr -s 1280x1024').  If the resolution was "current 1280 x
1024" then I would parse that and call back to os.system('xrandr -s

However, when I try the line (as in the code above):

currentRes =

it is complaining that xrandr_output is not a string.  (however, if I do a
print xrandr_output it prints fine)

I instead get the following error:

Traceback (most recent call last):
  File "", line 9, in <module>
    currentRes =
TypeError: expected string or buffer

What am I doing wrong?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list