How to remove "" from starting of a string if provided by the user

Bill Campbell bill at celestial.net
Tue Aug 11 17:18:47 EDT 2020


On Tue, Aug 11, 2020, Ganesh Pal wrote:
>The possible value of stat['server2'] can be either (a)
>"'/fileno_100.txt'" or (b) '/fileno_100.txt' .

def stripquotes(s):
    '''Strip leading single or double quotes to any depth'''
    import re
    pat = re.compile(r'^([\'"])(.*)(\1)$')
    slast = None
    while slast != s:
        slast = s
        s = pat.cub(r'\2', s)
    return s
# end stripquotes(s)

Bill
-- 
INTERNET:   bill at celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile:         (206) 947-5591  PO Box 820
Fax:            (206) 232-9186  Mercer Island, WA 98040-0820

Democracy is the theory that the common people know what they
want and deserve to get it good and hard. == H.L. Mencken


More information about the Python-list mailing list