You can also do this in one line using gdal.Info as so:

    epsg = int(gdal.Info(input, format='json')['coordinateSystem']['wkt'].rsplit('"EPSG","', 1)[-1].split('"')[0])

This does essentially the same thing as the answer provided by Lennert.  It reads the WKT representation of the file's spatial reference, then parses the string to extract the EPSG.

Note that this method is slightly more robust because gdal.Info is very flexible with the types of inputs it can take.  `input` may be a datasource, valid filepath, or anything within gdal's extensive [virtual file systems][1], which allows this method to accommodate a large number of potential use cases.

  [1]: http://www.gdal.org/gdal_virtual_file_systems.html