Skip to content

Flask Url shortening service #5

Open
@sr-murthy

Description

@sr-murthy

Hi

I feel that in chapter 1 of your book 'Learning Python Design Patterns', in the Flask URL shortening service, there might be an error in the method __increment_string in the Url class.

    def __increment_string(self, astring):
    """Increments string, that is:

         a -> b
         z -> aa
         az -> ba
         empty string -> a
    """
    if astring == '':
        return 'a'

    last_char = astring[-1]

    if last_char != 'z':
        return astring[:-1] + chr(ord(last_char) + 1)

    return self.__increment_string(astring[:-1]) + 'a'

This does not produce the expected output, for example:

In [4]: su._Url__increment_string('https://www.theguardian.com/travel/2016/dec/25/christmas-day-walk-the-city-of-london')
Out[4]: 'https://www.theguardian.com/travel/2016/dec/25/christmas-day-walk-the-city-of-londoo'

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