How to remove "" from starting of a string if provided by the user
Ganesh Pal
ganesh1pal at gmail.com
Mon Aug 10 14:35:48 EDT 2020
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 at X1:/tmp$ cat file2.py
#!/usr/bin/python
# Case 1 - server2 file is "'/fileno_100.txt'"
stat={}
stat['server1'] = '/fileno_100.txt'
stat['server2'] = "'/fileno_100.txt'"
if stat['server1'] == eval(stat['server2']):
print "OK"
# Case 2 - server2 file is '/fileno_100.txt'
stat['server2'] = "'/fileno_100.txt'"
if stat['server1'] == eval(stat['server2']):
print "OK"
# Case 3 - server2 file can be in (a) '/fileno_100.txt' or (b) :
"'/fileno_100.txt'" format
g1 at X1:/tmp$ python file2.py
OK
OK
More information about the Python-list
mailing list