1

Is there a way to get a list from my DB?

I have this in my code:

graph_avg_session_duration = AnalyticsData.query.filter_by(name='graph_sessions').first()
item = graph_avg_session_duration.value
print(item)

The value in the DB is: [0, 0, 50, 52]

But when I check the type it says string but I need this to be type list. I tried doing list(item) but this just makes a list item every char so doesn't work.

VC.One
  • 14,790
  • 4
  • 25
  • 57
DeadSec
  • 808
  • 1
  • 12
  • 38

1 Answers1

2

Don't know about your DB, but if you want to convert that string into a list and each element is a integer* you could try this, without using libraries:

list( int(x) for x in item.replace('[', '').replace(']','').split(', '))

*integer could be replaced with float etc

andreis11
  • 1,133
  • 1
  • 6
  • 10