How do I split this:
str = "['A20150710', 1.0]" to get 'A20150710'?
I tried the below line but not sure how to proceed from there:
str.split(',')
How do I split this:
str = "['A20150710', 1.0]" to get 'A20150710'?
I tried the below line but not sure how to proceed from there:
str.split(',')
 
    
    Use ast.literal_eval to convert string representation to a list and get the first item:
import ast
str = "['A20150710', 1.0]"
print(ast.literal_eval(str)[0])
# A20150710
 
    
    Split on , and remove punctuations
import string
str1 = "['A20150710', 1.0]"
str1=str1.split(',')[0]
str1.translate(None,string.punctuation) #'A20150710'
 
    
    Use eval to parse the string, then fetch the information you want
str = "['A20150710', 1.0]"
eval(str)[0] # A20150710
!!!Be careful!!! Using eval is a security risk, as it executes arbitrary Python expressions
