Accessing the data from SQLalchemy query object?How to randomly select an item from a list?Accessing the index in 'for' loops?How to know if an object has an attribute in PythonDetermine the type of an object?Why can't Python parse this JSON data?null object in Python?SQLAlchemy ORDER BY DESCENDING?SQLAlchemy: What's the difference between flush() and commit()?How to access environment variable values?“Large data” work flows using pandas

How to officially communicate to a non-responsive colleague?

Can a user sell my software (MIT license) without modification?

Using a found spellbook as a Sorcerer-Wizard multiclass

How did they achieve the Gunslinger's shining eye effect in Westworld?

What can plausibly explain many of my very long and low-tech bridges?

PhD - Well known professor or well known school?

Is using haveibeenpwned to validate password strength rational?

How did students remember what to practise between lessons without any sheet music?

Using "subway" as name for London Underground?

If you had a giant cutting disc 60 miles diameter and rotated it 1000 rps, would the edge be traveling faster than light?

How to Analytically Solve this PDE?

Interview not reimboursed if offer is made but not accepted

Is an early checkout possible at a hotel before its reception opens?

Why doesn’t a normal window produce an apparent rainbow?

Frame failure sudden death?

How to chain Python function calls so the behaviour is as follows

Movie about a boy who was born old and grew young

Should an arbiter claim draw at a K+R vs K+R endgame?

Do simulator games use a realistic trajectory to get into orbit?

Is the term 'open source' a trademark?

Why doesn't Adrian Toomes give up Spider-Man's identity?

When conversion from Integer to Single may lose precision

How does an ordinary object become radioactive?

Payment instructions allegedly from HomeAway look fishy to me



Accessing the data from SQLalchemy query object?


How to randomly select an item from a list?Accessing the index in 'for' loops?How to know if an object has an attribute in PythonDetermine the type of an object?Why can't Python parse this JSON data?null object in Python?SQLAlchemy ORDER BY DESCENDING?SQLAlchemy: What's the difference between flush() and commit()?How to access environment variable values?“Large data” work flows using pandas






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I am querying my database using the following command in python:



self.deleted_packages = model.Session.query(
model.Package).filter_by(state=model.State.DELETED)


And I am accessing the above value in pkg as show below:



for pkg in self.deleted_packages: 


The output in pkg is :



<Package id=563e0da3-6916-4158-bc9f-f11bf92d3240 
name=asdacaasas
title=asdacaasas
version= url= author= author_email= maintainer= maintainer_email= notes=
license_id=cc-by
type=dataset
owner_org=9b89900e-c4b8-413d-a8fe-edbe08641022
creator_user_id=30ad2d1c-f133-4458-9947-535e2718a898
metadata_created=2019-05-21 13:08:52.322015
metadata_modified=2019-05-21 13:08:59.946710
private=True
state=deleted
revision_id=5251e583-3a71-4189-8d4e-aaac8ac69927>


I just require the package id in a variable. And when I try to do the following:
p1=[x[0] for x in pkg]



I get the following error:



p1=[x[0] for x in pkg]
TypeError: 'Package' object is not iterable


Does someone know how can i store the value of just id : 563e0da3-6916-4158-bc9f-f11bf92d3240 in a variable from the above query result.?










share|improve this question















migrated from serverfault.com May 21 at 13:43


This question came from our site for system and network administrators.


















  • what library / package are you using ? SQLAlchemy ?

    – bruno desthuilliers
    May 21 at 13:47











  • @brunodesthuilliers , yes I am using SQLalchemy v1.3

    – argg
    May 21 at 14:04











  • @B.C can you please elaborate more on it?

    – argg
    May 21 at 14:05











  • @argg then have you searched the SQLAlchemy doc before posting here ? I'd be suprised if you didn't find the answer...

    – bruno desthuilliers
    May 21 at 14:08











  • Done @brunodesthuilliers, but why did you downvote.?

    – argg
    May 22 at 9:50

















-1















I am querying my database using the following command in python:



self.deleted_packages = model.Session.query(
model.Package).filter_by(state=model.State.DELETED)


And I am accessing the above value in pkg as show below:



for pkg in self.deleted_packages: 


The output in pkg is :



<Package id=563e0da3-6916-4158-bc9f-f11bf92d3240 
name=asdacaasas
title=asdacaasas
version= url= author= author_email= maintainer= maintainer_email= notes=
license_id=cc-by
type=dataset
owner_org=9b89900e-c4b8-413d-a8fe-edbe08641022
creator_user_id=30ad2d1c-f133-4458-9947-535e2718a898
metadata_created=2019-05-21 13:08:52.322015
metadata_modified=2019-05-21 13:08:59.946710
private=True
state=deleted
revision_id=5251e583-3a71-4189-8d4e-aaac8ac69927>


I just require the package id in a variable. And when I try to do the following:
p1=[x[0] for x in pkg]



I get the following error:



p1=[x[0] for x in pkg]
TypeError: 'Package' object is not iterable


Does someone know how can i store the value of just id : 563e0da3-6916-4158-bc9f-f11bf92d3240 in a variable from the above query result.?










share|improve this question















migrated from serverfault.com May 21 at 13:43


This question came from our site for system and network administrators.


















  • what library / package are you using ? SQLAlchemy ?

    – bruno desthuilliers
    May 21 at 13:47











  • @brunodesthuilliers , yes I am using SQLalchemy v1.3

    – argg
    May 21 at 14:04











  • @B.C can you please elaborate more on it?

    – argg
    May 21 at 14:05











  • @argg then have you searched the SQLAlchemy doc before posting here ? I'd be suprised if you didn't find the answer...

    – bruno desthuilliers
    May 21 at 14:08











  • Done @brunodesthuilliers, but why did you downvote.?

    – argg
    May 22 at 9:50













-1












-1








-1








I am querying my database using the following command in python:



self.deleted_packages = model.Session.query(
model.Package).filter_by(state=model.State.DELETED)


And I am accessing the above value in pkg as show below:



for pkg in self.deleted_packages: 


The output in pkg is :



<Package id=563e0da3-6916-4158-bc9f-f11bf92d3240 
name=asdacaasas
title=asdacaasas
version= url= author= author_email= maintainer= maintainer_email= notes=
license_id=cc-by
type=dataset
owner_org=9b89900e-c4b8-413d-a8fe-edbe08641022
creator_user_id=30ad2d1c-f133-4458-9947-535e2718a898
metadata_created=2019-05-21 13:08:52.322015
metadata_modified=2019-05-21 13:08:59.946710
private=True
state=deleted
revision_id=5251e583-3a71-4189-8d4e-aaac8ac69927>


I just require the package id in a variable. And when I try to do the following:
p1=[x[0] for x in pkg]



I get the following error:



p1=[x[0] for x in pkg]
TypeError: 'Package' object is not iterable


Does someone know how can i store the value of just id : 563e0da3-6916-4158-bc9f-f11bf92d3240 in a variable from the above query result.?










share|improve this question
















I am querying my database using the following command in python:



self.deleted_packages = model.Session.query(
model.Package).filter_by(state=model.State.DELETED)


And I am accessing the above value in pkg as show below:



for pkg in self.deleted_packages: 


The output in pkg is :



<Package id=563e0da3-6916-4158-bc9f-f11bf92d3240 
name=asdacaasas
title=asdacaasas
version= url= author= author_email= maintainer= maintainer_email= notes=
license_id=cc-by
type=dataset
owner_org=9b89900e-c4b8-413d-a8fe-edbe08641022
creator_user_id=30ad2d1c-f133-4458-9947-535e2718a898
metadata_created=2019-05-21 13:08:52.322015
metadata_modified=2019-05-21 13:08:59.946710
private=True
state=deleted
revision_id=5251e583-3a71-4189-8d4e-aaac8ac69927>


I just require the package id in a variable. And when I try to do the following:
p1=[x[0] for x in pkg]



I get the following error:



p1=[x[0] for x in pkg]
TypeError: 'Package' object is not iterable


Does someone know how can i store the value of just id : 563e0da3-6916-4158-bc9f-f11bf92d3240 in a variable from the above query result.?







python sqlalchemy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 at 16:28









B.C

155112




155112










asked May 21 at 13:37









arggargg

319




319




migrated from serverfault.com May 21 at 13:43


This question came from our site for system and network administrators.









migrated from serverfault.com May 21 at 13:43


This question came from our site for system and network administrators.














  • what library / package are you using ? SQLAlchemy ?

    – bruno desthuilliers
    May 21 at 13:47











  • @brunodesthuilliers , yes I am using SQLalchemy v1.3

    – argg
    May 21 at 14:04











  • @B.C can you please elaborate more on it?

    – argg
    May 21 at 14:05











  • @argg then have you searched the SQLAlchemy doc before posting here ? I'd be suprised if you didn't find the answer...

    – bruno desthuilliers
    May 21 at 14:08











  • Done @brunodesthuilliers, but why did you downvote.?

    – argg
    May 22 at 9:50

















  • what library / package are you using ? SQLAlchemy ?

    – bruno desthuilliers
    May 21 at 13:47











  • @brunodesthuilliers , yes I am using SQLalchemy v1.3

    – argg
    May 21 at 14:04











  • @B.C can you please elaborate more on it?

    – argg
    May 21 at 14:05











  • @argg then have you searched the SQLAlchemy doc before posting here ? I'd be suprised if you didn't find the answer...

    – bruno desthuilliers
    May 21 at 14:08











  • Done @brunodesthuilliers, but why did you downvote.?

    – argg
    May 22 at 9:50
















what library / package are you using ? SQLAlchemy ?

– bruno desthuilliers
May 21 at 13:47





what library / package are you using ? SQLAlchemy ?

– bruno desthuilliers
May 21 at 13:47













@brunodesthuilliers , yes I am using SQLalchemy v1.3

– argg
May 21 at 14:04





@brunodesthuilliers , yes I am using SQLalchemy v1.3

– argg
May 21 at 14:04













@B.C can you please elaborate more on it?

– argg
May 21 at 14:05





@B.C can you please elaborate more on it?

– argg
May 21 at 14:05













@argg then have you searched the SQLAlchemy doc before posting here ? I'd be suprised if you didn't find the answer...

– bruno desthuilliers
May 21 at 14:08





@argg then have you searched the SQLAlchemy doc before posting here ? I'd be suprised if you didn't find the answer...

– bruno desthuilliers
May 21 at 14:08













Done @brunodesthuilliers, but why did you downvote.?

– argg
May 22 at 9:50





Done @brunodesthuilliers, but why did you downvote.?

– argg
May 22 at 9:50












1 Answer
1






active

oldest

votes


















1














You should read the docs for SQLalchemy (I am getting this context from the comments).



There are a few examples examples that can highlight how you could get around your issue.



An example from the documentation linked in this answer (not relevant to your exact case!):



>>> for row in session.query(User, User.name).all():
... print(row.User, row.name)


With the output being:



<User(name='ed', fullname='Ed Jones', nickname='eddie')> ed
<User(name='wendy', fullname='Wendy Williams', nickname='windy')> wendy
<User(name='mary', fullname='Mary Contrary', nickname='mary')> mary
<User(name='fred', fullname='Fred Flintstone', nickname='freddy')> fred


So in your case the pkg variable (an object of the Package class) might be similar to the User object in the example above and the name contents is accessed by row.name.



So your case might have something like pkg.id






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56239684%2faccessing-the-data-from-sqlalchemy-query-object%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You should read the docs for SQLalchemy (I am getting this context from the comments).



    There are a few examples examples that can highlight how you could get around your issue.



    An example from the documentation linked in this answer (not relevant to your exact case!):



    >>> for row in session.query(User, User.name).all():
    ... print(row.User, row.name)


    With the output being:



    <User(name='ed', fullname='Ed Jones', nickname='eddie')> ed
    <User(name='wendy', fullname='Wendy Williams', nickname='windy')> wendy
    <User(name='mary', fullname='Mary Contrary', nickname='mary')> mary
    <User(name='fred', fullname='Fred Flintstone', nickname='freddy')> fred


    So in your case the pkg variable (an object of the Package class) might be similar to the User object in the example above and the name contents is accessed by row.name.



    So your case might have something like pkg.id






    share|improve this answer



























      1














      You should read the docs for SQLalchemy (I am getting this context from the comments).



      There are a few examples examples that can highlight how you could get around your issue.



      An example from the documentation linked in this answer (not relevant to your exact case!):



      >>> for row in session.query(User, User.name).all():
      ... print(row.User, row.name)


      With the output being:



      <User(name='ed', fullname='Ed Jones', nickname='eddie')> ed
      <User(name='wendy', fullname='Wendy Williams', nickname='windy')> wendy
      <User(name='mary', fullname='Mary Contrary', nickname='mary')> mary
      <User(name='fred', fullname='Fred Flintstone', nickname='freddy')> fred


      So in your case the pkg variable (an object of the Package class) might be similar to the User object in the example above and the name contents is accessed by row.name.



      So your case might have something like pkg.id






      share|improve this answer

























        1












        1








        1







        You should read the docs for SQLalchemy (I am getting this context from the comments).



        There are a few examples examples that can highlight how you could get around your issue.



        An example from the documentation linked in this answer (not relevant to your exact case!):



        >>> for row in session.query(User, User.name).all():
        ... print(row.User, row.name)


        With the output being:



        <User(name='ed', fullname='Ed Jones', nickname='eddie')> ed
        <User(name='wendy', fullname='Wendy Williams', nickname='windy')> wendy
        <User(name='mary', fullname='Mary Contrary', nickname='mary')> mary
        <User(name='fred', fullname='Fred Flintstone', nickname='freddy')> fred


        So in your case the pkg variable (an object of the Package class) might be similar to the User object in the example above and the name contents is accessed by row.name.



        So your case might have something like pkg.id






        share|improve this answer













        You should read the docs for SQLalchemy (I am getting this context from the comments).



        There are a few examples examples that can highlight how you could get around your issue.



        An example from the documentation linked in this answer (not relevant to your exact case!):



        >>> for row in session.query(User, User.name).all():
        ... print(row.User, row.name)


        With the output being:



        <User(name='ed', fullname='Ed Jones', nickname='eddie')> ed
        <User(name='wendy', fullname='Wendy Williams', nickname='windy')> wendy
        <User(name='mary', fullname='Mary Contrary', nickname='mary')> mary
        <User(name='fred', fullname='Fred Flintstone', nickname='freddy')> fred


        So in your case the pkg variable (an object of the Package class) might be similar to the User object in the example above and the name contents is accessed by row.name.



        So your case might have something like pkg.id







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 21 at 14:37









        B.CB.C

        155112




        155112





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56239684%2faccessing-the-data-from-sqlalchemy-query-object%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

            Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos

            Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020