import osgeo
import gdal
from osgeo import ogr
This is unnecessary , as you're not using the GDAL/OGR python bindings. Note the correct way to import gdal is "from osgeo import gdal"import ogr2ogr
import ogrinfo
ogr2ogr and ogrinfo are commandline programs not python modules. This should fail with an ImportError exception.string=str("ogr2ogr -f"+ ' "KML"'+" "+ 'throwthisaway.kml'+" "+'test.dgn')
Use a list instead, it's easier to read:cmd=["ogr2ogr", "-f", "KML", "throwthisaway.kml", "test.dgn"]
You can use subprocess.Popen if you want to get the ogr2ogr error message:proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
stdout,stderr=proc.communicate()
exit_code=proc.wait()
if exit_code: print stderr
else: print stdout