Fetch a value of SQLalchemy instrumentedattribute

2024/10/5 17:23:12

How can I fetch the value of a InstrumentedAttribute object in SQLalchemy:

(Pdb) ResultLine.item_reference_1
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x793dc90>

The above statement prints me the sqlalchemy object.

What I actually need is the value associated with it.

Answer

There is no value associated with an InstrumentedAttribute; you are looking at a table declaration, not a result set. InstrumentedAttribute is used to define a relationship to another table, for example.

Query the database for results, and the resulting objects will have the reference filled in for you:

 for res in session.query(ResultLine).filter(somefilter):print res.item_reference_1
https://en.xdnf.cn/q/70459.html

Related Q&A

python super calling child methods

There are numerous questions on the usage of super() but none of them appears to answer my question. When calling super().__init__() from a subclass, all method calls in the super-constructor are actua…

How to create space between subplots? [duplicate]

This question already has answers here:Manipulation on vertical space in matplotlib subplots(3 answers)Closed 2 years ago.The title pretty much says it all. I have a notebook containing two subplots an…

How to (re)name an empty column header in a pandas dataframe without exporting to csv

I have a pandas dataframe df1 with an index column and an unnamed series of values. I want to assign a name to the unnamed series. The only way to do this that I know so far is to export to df1.csv usi…

Capturing the video stream from a website into a file

For my image classification project I need to collect classified images, and for me a good source would be different webcams around the world streaming video in the internet. Like this one:https://www.…

Recreating time series data using FFT results without using ifft

I analyzed the sunspots.dat data (below) using fft which is a classic example in this area. I obtained results from fft in real and imaginery parts. Then I tried to use these coefficients (first 20) to…

python BeautifulSoup get all href in Children of div

I am new to python and Ive been trying to get links and inner text from this html code : <div class="someclass"><ul class="listing"><li><a href="http://lin…

Python TypeError: sort() takes no positional arguments

I try to write a small class and want to sort the items based on the weight. The code is provided, class Bird:def __init__(self, weight):# __weight for the private variableself.__weight = weightdef wei…

Trouble with basemap subplots

I need to make a plot with n number of basemap subplots. But when I am doing this the all the values are plotted on the first subplot.My data is a set of n matrixes, stored in data_all.f, map = plt.sub…

Remove circular references in dicts, lists, tuples

I have this following really hack code which removes circular references from any kind of data structure built out of dict, tuple and list objects.import astdef remove_circular_refs(o):return ast.liter…

how to change image format when uploading image in django?

When a user uploads an image from the Django admin panel, I want to change the image format to .webp. I have overridden the save method of the model. Webp file is generated in the media/banner folder b…