Country Code
code_to_alpha2
converts both alpha-3 and alpha-2 codes to alpha-2 format, and returning None
in the absence of a match. This can also be used to validate if a given string is a country code.
The function is designed to accept inputs in both lower and upper case formats by default. However, certain scenarios may require the function to only match upper case codes. In such cases, CountryWrangler provides an option to enable upper case code matching by setting the upper_only
parameter to True
.
Supports misused UK
codes!
Although UK
for United Kingdom is not an ISO alpha-2 code it's misuse is common practice. CountryWrangler automatically converts UK
to GB
.
This behavior can be disabled by setting the optional parameter allow_uk=False
.
Usage Example
Basic Usage | |
---|---|
The conversion of UK
to GB
can be diabled by passing the option allow_uk=False
. Once disabled None
is returned for UK
values.
OPTIONS - UK conversion disabled | |
---|---|
To only allow the matching of upper case inputs pass the upper_only=True
option.