The UN maintains M49 codes for every country, continent and some regions. There is not one for countries in the EU, but there are several others for various political/economic regions. I'm not sure how many non-UN datasets use these codes but they do exist. I'm dropping the UN's M49 methodology page below, as well as the wikipedia page on M49 (it has all of ...
Foreword: This answer does not contain corrections to the author's
Before digging into the scripting I highly recommend to investigate approaches with no coding.
Here I tried to describe a couple of options that may be useful.
Option 1. Looking for open public data
Try exploring some address catalogues provided by government, city administrations and ...