from subprocess import Popen, PIPE
ifcfg_lines = Popen("/sbin/ifconfig fxp0",shell=True,stdout=PIPE).stdout.readlines()
x = string.split(ifcfg_lines[3])[1]
For a little more elegance, hide the details:
def getBSDIP():
from subprocess import Popen, PIPE
import string
CURRENT = Popen("/sbin/ifconfig fxp0", shell=True,stdout=PIPE).stdout.readlines()
return(string.split(CURRENT[3])[1])
If you are going to use subprocess to do this then elegance is a bit limited because you are essentially doing something like screenscraping, except here you are scriptscraping. If you want a truly general solution, use the socket library, i.e. let Python handle the portability.
Often, when you look at a bit of code and you wish that there was a better cleaner way to do it, this means that you need to question your assumptions, and change the algorithm or architecture of the solution.