Aug-08-2017, 12:58 AM
Aug-08-2017, 01:28 AM
I would say the first one is the most readable code of the three. I would also consider a regular expression or:
if s.startswith("'") and s.endswith("'")
Aug-08-2017, 01:34 AM
+1 for ichabod's suggestion
Aug-08-2017, 06:06 AM
(Aug-08-2017, 01:28 AM)ichabod801 Wrote: [ -> ]I would say the first one is the most readable code of the three. I would also consider a regular expression or:i'm going to be removing the quotes. anything better than:
if s.startswith("'") and s.endswith("'")
if s.startswith("'") and s.endswith("'"): s = s[1:-1]?
FYI, s comes from repr() which will have the quotes if a string is given to it, but those will be awkward for the usage, which is to be part of a filename.
Aug-08-2017, 06:10 AM
s = "'some'string'" print s print s.strip("'")
Output:'some'string'
some'string
Given the additional info I would consider skipping the if part and clearing the quote even if only in begining or only at the endAug-16-2017, 04:15 AM
if there are quotes in the middle, i want to keep them. i'm removing the quotes that repr() adds to a string, but it might have not been a string. i should make some variant code for unicode (v2), bytes (v3), and bytearray.