Re: Linq to Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hrishy

    Re: Linq to Python

    Hi

    If i rephrase my question how will i do this in Python



    Watch this query on the page Where he joins all different kind of things with ease and elegance(as per my opinion)

    Code:
    var stoogeGuys = 
    Beginning with the XML source
    from xmlGuys in xmlSource.Descendants("Stooge")
    Join to the array on the common element "stoogeName"
    join arrayGuys in familyFacts 
    on xmlGuys.Element("stoogeName").Value equals arrayGuys.stoogeName
    Join to the database on the common element "stoogeName"
    join dbGuys in stoogeContext.stoogeTables 
    on xmlGuys.Element("stoogeName").Value equals dbGuys.stoogeName 
    select new
    {
    firstName    = dbGuys.stoogeName,
    familyName   = arrayGuys.familyName,
    birthDate    = xmlGuys.Element("birthDate").Value,
    deathDate    = xmlGuys.Element("deathDate").Value,
    hairCutStyle = dbGuys.stoogeHaircut,
    };
    regards
    Hrishy



  • sturlamolden

    #2
    Re: Linq to Python

    On 25 Sep, 12:06, hrishy <hris...@yahoo. co.ukwrote:
    var stoogeGuys =
         Beginning with the XML source
         from xmlGuys in xmlSource.Desce ndants("Stooge" )
         Join to the array on the common element "stoogeName "
         join arrayGuys in familyFacts
               on xmlGuys.Element ("stoogeName"). Value equals arrayGuys.stoog eName
         Join to the database on the common element "stoogeName "
         join dbGuys in stoogeContext.s toogeTables
               on xmlGuys.Element ("stoogeName"). Value equals dbGuys.stoogeNa me
         select new
         {
            firstName    = dbGuys.stoogeNa me,
            familyName   = arrayGuys.famil yName,
            birthDate    = xmlGuys.Element ("birthDate").V alue,
            deathDate    = xmlGuys.Element ("deathDate").V alue,
            hairCutStyle = dbGuys.stoogeHa ircut,
         };
    [/code]

    That is a for loop over xmlGuys in xmlSource.Desce ndants("Stooge" ).
    Those joins are e.g. dictionary lookups, and finally an object with
    names, birthdates, etc. are appended to the list stoogeGuys.






    Comment

    • sturlamolden

      #3
      Re: Linq to Python

      On 25 Sep, 12:06, hrishy <hris...@yahoo. co.ukwrote:
      Code:
      var stoogeGuys =
           Beginning with the XML source
           from xmlGuys in xmlSource.Descendants("Stooge")
           Join to the array on the common element "stoogeName"
           join arrayGuys in familyFacts
                 on xmlGuys.Element("stoogeName").Value equals arrayGuys.stoogeName
           Join to the database on the common element "stoogeName"
           join dbGuys in stoogeContext.stoogeTables
                 on xmlGuys.Element("stoogeName").Value equals dbGuys.stoogeName
           select new
           {
              firstName    = dbGuys.stoogeName,
              familyName   = arrayGuys.familyName,
              birthDate    = xmlGuys.Element("birthDate").Value,
              deathDate    = xmlGuys.Element("deathDate").Value,
              hairCutStyle = dbGuys.stoogeHaircut,
           };
      It could e.g. look like this in Python:

      stoogeGuys = []
      for xmlGuys in xmlSource.Desce ndants["Stooge"]:
      arrayGuys = familyFacts[xmlGuys.stoogeN ame]
      dbGuys = stoogeContext.s toogeTables[xmlGuys.stoogeN ame]
      stoogeGuys += \
      [{'firstName': dbGuys.stoogeNa me,
      'familyName': arrayGuys.famil yName,
      'birthDate': xmlGuys.birthDa te,
      'deathDate': dbGuys.deathDat e,
      'hairCutStyle': dbGuys.stoogeHa ircut}]

      Comment

      Working...