python-restcountries icon indicating copy to clipboard operation
python-restcountries copied to clipboard

Inconsistency in the use of the name parameter in the documentation code examples

Open RomarioNzenguele opened this issue 8 months ago • 0 comments

Hello,

I noticed that some code examples in the documentation define a name parameter, but it is never used, as the country name is hardcoded as 'France'. This reduces the usefulness of the examples, making them static.

Suggested improvement: replace the hardcoded value with the name parameter to make the functions more dynamic and reusable. For example:

def foo(name):
    country_list = rapi.get_countries_by_name(name)

The same situation occurs in the filtering example as well.

I believe this small change could make the examples clearer and more practical for those learning to use the library.

Otherwise, if you find it helpful, the code could be updated as follows:

# Import the RestCountries API wrapper
from restcountries import RestCountryApiV2 as rapi

# Define a function that retrieves country information by name
def foo(name):
    """
    Retrieves country information using the RestCountries API.
    
    Args:
        name (str): The name of the country to search for
        
    Returns:
        list: A list of country objects matching the search term
    """
    return rapi.get_countries_by_name(name)

# Example: Search for France
country_list = foo('France')

# Process and display the results
for country in country_list:
    print(country)  # Prints the string representation of the country object 

Thank you for the great work!

RomarioNzenguele avatar May 08 '25 22:05 RomarioNzenguele