Created
December 4, 2019 12:15
-
-
Save AntonFriberg/ed4b904d81dade6e4a4c908a288ff279 to your computer and use it in GitHub Desktop.
S3 partition extraction in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
regex = r"(year|month|day|hour)=(\d+)" | |
test_str = "s3://bucket/datalake/year=2019/month=12/day=02/hour=06" | |
matches = re.finditer(regex, test_str) | |
partition = {match.group(1): int(match.group(2)) for match in matches} | |
print(partition) | |
# {'year': 2019, 'month': 12, 'day': 2, 'hour': 6} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment