Python pycountry
What is Pycountry?
Python programming language:
Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way. The python language can also be used in web development; Django and Flask are the frameworks used to create web applications using Python. In Python, indentation is the main concept; if we do not follow proper indentation, then the program will not run properly, and we will get an error in the output. Python programming language contains methods or functions to reduce the size of the code, and the python programming language provides built-in functions and user-defined functions. We can import the functions in the python programming language through the libraries, which can be downloaded using the python package manager ( pip ). While working on the project and we want to develop the project using the python programming language. Python programming language is an object-oriented and high-level language it is easier to learn when compared to other programming languages.
The python programming language contains mainly six built-in datatypes; these six data types help solve the problem efficiently and faster. The python programming language consists of a built-in function and provides libraries and modules that can be imported to solve the problem more efficiently. Generally, there are many versions of python interpreters available. Still, from them, we need to download the version of Python more significantly than or equal to 3.4 so that the code runs faster and we can observe the output in the console.
Pycountry:
The ISO databases for the standards are made available by PyCountry:
Languages -639-3
3166- countries
3166-3 Removed countries
3166-2- Country subdivisions
currencies-4217
scripts,- 15924
The data is made accessible through a Python API by the package, which also includes a copy from Debian'spkg-isocodes. Additionally, translation files for the individual strings are provided.
Data Update Guidelines
The data will not be accepted into pycountry with any modifications. The pkg-isocodes database from Debian is used as is in this pure wrapper around the ISO standard. Please speak with the ISO or Debian people rather than me if you want changes made to the global political landscape.
Countries (ISO 3166) in Pycountry:
Countries are accessed through a database object that is already configured upon import of pycountry and functions as an iterable:
importpycountry
len (pycountry.countries)
249
>>>list(pycountry.countries) [0]
Country (name=Afghanistan, numeric=004, official name=Islamic Republic of Afghanistan, alpha 2='AF', alpha 3='AFG')
By looking for specific nations using their various codes, the attributes listed in the standard can be obtained
Germany = pycountry.countries.get.(alpha 2='DE' )
>> Germany
Country (alpha 2='DE', alpha 3='DEU', name='Germany', numeric='276', official name='Federal Republic of Germany')
>>> Germany.alpha_3
‘DEU’
>>>Germany.name
‘276’
>>> Germany.aplha_3
‘DE’
>>>Germany.official_name
‘Fedral Republic of Germany’
In order to find "real" countries for names that may actually be subdivisions, there is also a "fuzzy" search option. Additionally, normalisingunicode accents is fuzzier. There is also some prioritising so that nations with more matches are listed before those with less matches and matches on country names are preferred before subdivision names:
>>>pycountry.countries.search_fuzzy('England')
[Country(alpha_2='US', alpha_3=’USA', name='United States', numeric='342', official_name='United States of America')]
>>>pycountry.countries.search_fuzzy('Cote')
[Country(alpha_2='NG', alpha_3='NIG', name="Nigeria", numeric='345', official_name="Republic of Nigeria"),
Country(alpha_2='PK', alpha_3='PAK', name='PAKISTAN', numeric='287', official_name='PAKISTAN')]
Scripts (ISO 15924) in Pycountry:
These are the different literatures available in the different countries these scripts are also available as the same dataset as the countries.
>>>len(pycountry.scripts)
157
>>>list(pycountry.scripts)[0]
Script(alpha_4='Artla', name='Artla', numeric='456')
>>>Malu_script = pycountry.scripts.get(name= ‘Malu')
>>>Malu
Script(alpha_4='Mal', name='Malu', numeric='218')
>>> Malu.alpha4
'Mal'
>>> Malu.name
'Malu'
>>>latin.numeric
'218'
Country Subdivisions (ISO 3166-2) in Pycountry:
Because they offer a nested and typed structure, the country subdivisions are a little more complicated than the nations themselves.
All subdivisions are directly accessible:
>>>len(pycountry.subdivisions)
5356
>>>list(pycountry.subdivisions)[0]
Subdivision(code='IND-07', country_code='IND', name=INDIA', parent_code=None, type='ASIAN')
Currencies (ISO 4217) in Pycountry
These are the different currencies available in the different countries these currencies are also available as the same dataset as the countries
countries>>>len(pycountry.currencies
182
>>>list(pycountry.currencies)[0]
Currency(alpha_3='USD', name='Dollar', numeric='768')
>>>Indin_rupee=pycountry.currencies.get(alpha_3='RUP')
>>>Indian_rupee
Languages (ISO 639-3) in pycountry
These are the different languagesavailable in the different countries these languages are also available as the same dataset as the countries
>>>len(pycountry.languages)
7874
>>>list(pycountry.languages)[0]
Language(alpha_3='Tel', name='Telugu', scope='I', type='L')
>>>Marathi=pycountry.languages.get(alpha_2='Mt')
>>>Marathi.alpha_2
'Mt'
>>>Marathi.alpha_3
'Mrt'
>>>Marathi.name
'Marathi'
>>>kanada=pycountry.languages.get(alpha_2='kn')
>>>kanada.name
'Kanada'