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

2020-08-12 Thread Serhiy Storchaka
12.08.20 18:53, MRAB пише: > I would suggest: > while s[ : 1] in {'"', "'"} and s[ : 1] == s[-1 : ]: > ... s = s[1 : -1] And the condition can be written as s[ : 1] == s[-1 : ] in {'"', "'"} or more efficiently as s and s[0] == s[-1] in '\'"' -- https://mail.python.org/mailm

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

2020-08-12 Thread Matt Wheeler
On Tue, 11 Aug 2020, 02:20 Ganesh Pal, wrote: > The possible value of stat['server2'] can be either (a) > "'/fileno_100.txt'" or (b) '/fileno_100.txt' . > > How do I check if it the value was (a) i.e string started and ended > with a quote , so that I can use ast.literal_eval() > BAFP > def ma

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

2020-08-12 Thread MRAB
On 2020-08-11 20:43, Dennis Lee Bieber wrote: On Tue, 11 Aug 2020 14:17:39 -0400, Joel Goldstick declaimed the following: [snip] Warning -- it will fail if the input is just a pair of quotes or pair of apostrophes -- improvement is while s and s[0] in ['"', "'"]: ... if s[0] == s[-1]:

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

2020-08-11 Thread Bill Campbell
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 = Non

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

2020-08-11 Thread Akkana Peck
> > On 2020-08-11 02:20, Ganesh Pal wrote: > > > How do I check if it the value was (a) i.e string started and ended > > > with a quote Of course the original question was simple and there have been lots of solutions given. But I find this comes up periodically, and I'm always leery of using som

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

2020-08-11 Thread Joel Goldstick
On Tue, Aug 11, 2020 at 12:26 PM MRAB wrote: > > On 2020-08-11 02:20, Ganesh Pal wrote: > > The possible value of stat['server2'] can be either (a) > "'/fileno_100.txt'" or (b) '/fileno_100.txt' . > > How do I check if it the value was (a) i.e string started and ended > with a quote , so that I

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

2020-08-11 Thread MRAB
On 2020-08-11 02:20, Ganesh Pal wrote: > The possible value of stat['server2'] can be either (a) "'/fileno_100.txt'" or (b) '/fileno_100.txt' . > How do I check if it the value was  (a) i.e string started and ended with a quote , so that I can use ast.literal_eval() > >>> import ast > >>> stat

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

2020-08-10 Thread Ganesh Pal
The possible value of stat['server2'] can be either (a) "'/fileno_100.txt'" or (b) '/fileno_100.txt' . How do I check if it the value was (a) i.e string started and ended with a quote , so that I can use ast.literal_eval() >>> import ast >>> stat = {} >>> stat['server2'] = "'/fileno_100.txt'" >

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

2020-08-10 Thread MRAB
On 2020-08-10 19:35, Ganesh Pal wrote: How to remove " from the starting and ending of a string , before comparison . Here is an example and my solution wtih eval ( I am advised not to use this one) , please suggest an alternative . I am on linux and python 2.7 g1@X1:/tmp$ cat file2.py #!/usr/bi

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

2020-08-10 Thread Cameron Simpson
On 11Aug2020 00:05, Ganesh Pal wrote: >How to remove " from the starting and ending of a string , before >comparison . Here is an example and my solution wtih eval ( I am advised >not to use this one) , please suggest an alternative . I am on linux and >python 2.7 Indeed. Using eval is extremely

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

2020-08-10 Thread Ganesh Pal
How to remove " from the starting and ending of a string , before comparison . Here is an example and my solution wtih eval ( I am advised not to use this one) , please suggest an alternative . I am on linux and python 2.7 g1@X1:/tmp$ cat file2.py #!/usr/bin/python # Case 1 - server2 file is "'/f