This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: String functions lstrip are not working properly when you have escape sequence
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Kiran Kotari, ethan.furman
Priority: normal Keywords:

Created on 2015-12-30 02:11 by Kiran Kotari, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg257223 - (view) Author: Kiran Kotari (Kiran Kotari) Date: 2015-12-30 02:11
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']
msg257224 - (view) Author: Kiran Kotari (Kiran Kotari) Date: 2015-12-30 02:26
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']
msg257225 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-12-30 02:39
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
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70167
2015-12-30 02:39:09ethan.furmansetstatus: open -> closed

nosy: + ethan.furman
messages: + msg257225

resolution: not a bug
stage: resolved
2015-12-30 02:26:36Kiran Kotarisetmessages: + msg257224
2015-12-30 02:25:53Kiran Kotarisetfiles: - string_fun_error.py
2015-12-30 02:11:39Kiran Kotaricreate