Returns a list containing the values of all environment variables whose names have a given prefix followed by an integer, starting from 0, until no more variables with that prefix are found.
(prefix: str)
| 9 | |
| 10 | |
| 11 | def get_numbered_env_vars_with_prefix(prefix: str) -> list[str]: |
| 12 | """ |
| 13 | Returns a list containing the values of all environment variables whose names have a given prefix followed by an |
| 14 | integer, starting from 0, until no more variables with that prefix are found. |
| 15 | """ |
| 16 | db_urls = [] |
| 17 | i = 0 |
| 18 | while True: |
| 19 | db_url = os.getenv(f"{prefix}{i}") |
| 20 | if not db_url: |
| 21 | break |
| 22 | db_urls.append(db_url) |
| 23 | i += 1 |
| 24 | return db_urls |