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
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
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]:
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
> > 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
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
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
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'"
>
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
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 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
11 matches
Mail list logo