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
- Fix-Gradient effect turning to gray in after effects
- How to blur an image in python?
- ModuleNotFoundError: No module named 'whois' in Python GoviralHost Without Terminal
- How to Convert Image to Pencil Sketch in Python?
- AttributeError: module 'urllib' has no attribute 'request' - Python
- How to Extract audio from video files using python?
- PermissionError: [Errno 13] Permission denied: 'shampoo_sales.csv' - Python
- [WinError 145] The directory is not empty: 'FolderPath' - Python
Related Article