Skip to content

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

@RomarioNzenguele

Description

@RomarioNzenguele

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions