0

I am working with flask and SQLalchemy, everything is coming together, but when I want to query the database to return data, it is simply returning the object, and not the information, for example the column info, inside the object.

Class

class stock_info(db.Model):
    #information in here#

When Querying Database

            myStock = stock_info.query.get(6)
            print("This is the info: ", myStock)

Output

<stock_info 6>

It is returning the correct data, but it is just showing me the object, how can I return what is inside eg the column data and then I am parsing the info after that etc.,

Do I need to put it into a dataframe or like select which column I would like to see?

NewCoder18
  • 310
  • 1
  • 9
  • Do you want to access the data within the object, or fetch the raw data without the object? – snakecharmerb Jul 03 '21 at 19:33
  • I want to access the data within the object, for example what I am trying to do is get everything from the first column '"stock_name", I am trying to see if the stock is already there so I do not need to spend money on an API call to IEXfinance, and I can just query the database and then use the data that is already saved, for use in my algorithm, that is what I am going for here. – NewCoder18 Jul 03 '21 at 19:36

1 Answers1

1

mystock is the object and which has the info you need.

For accessing a specific column from mystock object, you can do it this way

mystock.stock_name

which would return the value of stock_name column of the selected row.

You can furthur read the docs

charchit
  • 1,492
  • 2
  • 6
  • 17
  • Wow, literally was that all I was missing? I feel so dumb, thank you, sorry I am new to working with databases but I should have figured that. – NewCoder18 Jul 03 '21 at 21:19