S
S
semen79072020-06-27 22:07:41
Python
semen7907, 2020-06-27 22:07:41

How to convert str to list?

Tell me, I’m deriving a string from the database (mysql) and I don’t know how to convert it to the desired form

. As an example, this code:

mystr = "-0.09634063, 0.12095481, -0.00436332, -0.07643753, 0.0080383, 0.01902981" 
print([mystr])
результат выполнения такой:
>> ['-0.09634063, 0.12095481, -0.00436332, -0.07643753, 0.0080383, 0.01902981']


And I need to get this result:

mystr = [-0.09634063, 0.12095481, -0.00436332, -0.07643753, 0.0080383, 0.01902981]
print([mystr])
>> 


Or the problem is probably that the data was originally recorded in the database as a string, then again the question is, what type should I use for the record so that it is not displayed as a string, I can only write these values ​​​​in text

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
semen7907, 2020-06-28
@semen7907

Managed to solve (convert) in this way: np.fromstring(mystr , dtype=float, sep=', ')

I
i1yas, 2020-06-27
@i1yas

print([mystr.split(', ')])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question