generated from Hazel/python-project
feat: updated readme
This commit is contained in:
parent
070982ee03
commit
32597c1c9c
19
README.md
19
README.md
@ -28,7 +28,7 @@ except ValueError:
|
||||
|
||||
### Creating country class
|
||||
|
||||
You can call create an instance of `pycountry_wrapper.Country` in multiple slightly different ways.
|
||||
You can call create an instance of `Country` in multiple slightly different ways.
|
||||
|
||||
The [**ISO 3166-1**](https://en.wikipedia.org/wiki/ISO_3166-1) standart can either use 2 or 3 letters (alpha_2 or alpha_3).
|
||||
|
||||
@ -44,15 +44,20 @@ Country.from_alpha_2("DE")
|
||||
Country.from_alpha_3("DEU")
|
||||
```
|
||||
|
||||
If you want to use fuzzy search, you will have to use `Country.from_fuzzy()`.
|
||||
If the country can't be found it will raise a `EmptyCountryException` or use the fallback defined in `config.fallback_country`.
|
||||
|
||||
Alternatively you can get an instance of `Country` by using `Country.search`. This will return `None` if no country was found.
|
||||
|
||||
I also implemented a null-object pattern of `Country`, meaning you can get an `EmptyCountry` object. If you create a country from this object you'll get an instance of `Country` if it was found, and an instance of `EmptyCountry` if it wasn't.
|
||||
|
||||
```python
|
||||
from pycountry_wrapper import Country
|
||||
empty = EmptyCountry("InvalidCountry")
|
||||
print(type(empty)) # <class 'pycountry_wrapper.country.EmptyCountry'>
|
||||
|
||||
Country.from_fuzzy("Deutschland")
|
||||
found = EmptyCountry("US")
|
||||
print(type(found)) # <class 'pycountry_wrapper.country.Country'>
|
||||
```
|
||||
|
||||
|
||||
### Accessing information
|
||||
|
||||
There are only a handful (readonly) attributes.
|
||||
@ -60,10 +65,12 @@ There are only a handful (readonly) attributes.
|
||||
```python
|
||||
from pycountry_wrapper import Country
|
||||
|
||||
country = Country.from_alpha_2("DE")
|
||||
country = Country("DE")
|
||||
|
||||
country.name
|
||||
country.alpha_2
|
||||
country.alpha_3
|
||||
country.official_name
|
||||
```
|
||||
|
||||
If you have an `EmptyCountry` these attributes will all be `None`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user