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.<br>
<br>I have:<br><br>#! /usr/bin/python<br><br>import sys<br>import os<br>import re<br><br>re_currentResolution = re.compile(r'current \d{4}\sx\s\d{3,4}')<br>xrandr_output = os.popen('xrandr').readlines()<br>
currentRes = re_currentResolution.search(xrandr_output)<br>print currentRes.group(0)<br><br>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 1024x768').<br>
<br>However, when I try the line (as in the code above):<br><br>currentRes = re_currentResolution.search(xrandr_output)<br><br>it is complaining that xrandr_output is not a string.  (however, if I do a print xrandr_output it prints fine)<br>
<br>I instead get the following error:<br><br>Traceback (most recent call last):<br>  File "change_res.py", line 9, in <module><br>    currentRes = re_currentResolution.search(xrandr_output)<br>TypeError: expected string or buffer<br>
<br>What am I doing wrong? <br><br>Thanks.<br><br>Kevin<br><br>