COUNTRY INFO PROGRAM:
I want to retrieve the country information using the 'countryinfo' library. I have installed countryinfo python package using pip.
pip install countryinfo
CODE:
To get country information and print basic country information using python, import CountryInfo,
from countryinfo import CountryInfo def get_country_info(country_name): try: country = CountryInfo(country_name) return { 'capital': country.capital(), "Region": country.region(), "Currencies": country.currencies(), "Languages": country.languages(), } except Exception as e: print(f"Error: {e}") if __name__ == "__main__": country_name = input("Enter the country name: ") country_details = get_country_info(country_name) print(country_details)
I got this following error while executing a python program.
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 49: character maps to <undefined>.
SOLUTION:
This problem is related to the character encoding. To handle this issue use encoding utf-8.
country_info = json.load(open(file_path,encoding='utf-8'))
VIDEO GUIDE:
Post your comments / questions
Recent Article
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
Related Article