Skip to content

String functions lstrip are not working properly when you have escape sequence #70167

Closed

Description

@kirankotari
BPO 25979
Nosy @ethanfurman

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-12-30.02:39:09.720>
created_at = <Date 2015-12-30.02:11:39.827>
labels = ['invalid', 'type-bug', 'expert-2to3']
title = 'String functions lstrip are not working properly when you have escape sequence'
updated_at = <Date 2015-12-30.02:39:09.706>
user = 'https://bugs.python.org/KiranKotari'

bugs.python.org fields:

activity = <Date 2015-12-30.02:39:09.706>
actor = 'ethan.furman'
assignee = 'none'
closed = True
closed_date = <Date 2015-12-30.02:39:09.720>
closer = 'ethan.furman'
components = ['2to3 (2.x to 3.x conversion tool)']
creation = <Date 2015-12-30.02:11:39.827>
creator = 'Kiran Kotari'
dependencies = []
files = []
hgrepos = []
issue_num = 25979
keywords = []
message_count = 3.0
messages = ['257223', '257224', '257225']
nosy_count = 2.0
nosy_names = ['ethan.furman', 'Kiran Kotari']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue25979'
versions = ['Python 3.5']

Activity

  1. kirankotari commented on Dec 30, 2015

    kirankotarimannequin
    MannequinAuthor

    In this python code I am collecting list of folders present in the given location path with parent folder and print the folder names (output went wrong due to escape sequence values with lstrip.)
    Note :
    "\a \b \f \r \v \0 \1" are working fine.
    "\c \e \n \ne \t \te" went wrong.

    Folder Structure :
    parent ->
    cat
    eat
    east
    next
    nest
    test

    Wrong Output :
    Path: .\parent\, List: ['cat', 'st', '', 'st', 'xt', 'st']

  2. kirankotari commented on Dec 30, 2015

    kirankotarimannequin
    MannequinAuthor

    In this python code I am collecting list of folders present in the given location path with parent folder and print the folder names (output went wrong due to escape sequence values with lstrip.)
    Note :
    "\a \b \f \r \v \0 \1" are working fine.
    "\c \e \n \ne \t \te" went wrong.

    Python Code :
    import glob as g

    class Folders:
        def __init__(self, path, parent_folder_name):
            self.path = path + parent_folder_name + '\\'
            self.parent_folder_name = parent_folder_name
    
        def showFolders(self):
            folders = [lst.lstrip(self.path) for lst in  g.glob(self.path + '*')]
            print('Path: '+self.path+ ', List: ',folders)
        pass
    
    if __name__ == "__main__":
    	obj = Folders(path='.\\', parent_folder_name='parent')
    	obj.showFolders()

    Folder Structure :
    parent ->
    cat
    eat
    east
    next
    nest
    test

    Wrong Output :
    Path: .\parent\, List: ['cat', 'st', '', 'st', 'xt', 'st']

  3. ethanfurman commented on Dec 30, 2015

    @ethanfurman
    Member

    lstrip() works by removing any of the characters in its argument, in any order; for example:

    'catchy'.lstrip('cat')
    # 'hy'

    'actchy'.lstrip('tac')
    # 'hy'

    is stripping, from the left, all 'c's and all 'a's and all 't's -- not just the first three, and order does not matter.

    The docs: https://docs.python.org/3/library/stdtypes.html?highlight=lstrip#str.lstrip

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-2to3type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions