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

            Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

            Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

            What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company