Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 446741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:30:03+00:00 2026-05-12T21:30:03+00:00

I know next to nothing about Python and I’m using scons. (if you’re reading

  • 0

I know next to nothing about Python and I’m using scons. (if you’re reading this and know Python but not scons, you can probably help me!)

Could someone help me out and explain how I could have a variable that contains two lists? I’m not sure of the syntax. Is this right?

buildinfo = // how do you initialize a variable that has fields?
buildinfo.objectFiles = []; // list of the object files
buildinfo.sourceFiles = []; // list of the source files

If I have a function f() that returns a variable of this structure, what’s the shortest way to append f()’s return value onto both lists? (Really f() is Sconscript() but never mind.)

// call f() several times and append the results onto buildinfo
buildinfo_sub = f(...);
buildinfo.objectFiles.append(buildinfo_sub.objectFiles);
buildinfo.sourceFiles.append(buildinfo_sub.sourceFiles);
buildinfo_sub = f(...);
buildinfo.objectFiles.append(buildinfo_sub.objectFiles);
buildinfo.sourceFiles.append(buildinfo_sub.sourceFiles);
buildinfo_sub = f(...);
buildinfo.objectFiles.append(buildinfo_sub.objectFiles);
buildinfo.sourceFiles.append(buildinfo_sub.sourceFiles);

Is there a shorter way? this isn’t too long but it’s long enough to be error-prone.

edit: or better yet, I want to define a simple class that has two fields, objectFiles and sourceFiles, and if I call

object1.append(object2)

then object1 will append object2’s objectFiles and sourceFiles fields onto its own, so I could just do:

buildinfo = BuildInfo([],[]);
buildinfo.append(f(...));
buildinfo.append(f(...));
buildinfo.append(f(...));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:30:04+00:00Added an answer on May 12, 2026 at 9:30 pm

    How about something like this:

    class BuildInfo(object):
        def __init__(self, objectFiles = [], sourceFiles = []):
            self.objectFiles = objectFiles
            self.sourceFiles = sourceFiles 
        def append(self, build_info):
            self.objectFiles.extend(build_info.objectFiles)
            self.sourceFiles.extend(build_info.sourceFiles)
    

    To use it you would then say:

    a = BuildInfo() #uses default value of an empty list for object/sourceFiles
    b = BuildInfo(["hello.dat", "world.dat"], ["foo.txt", "bar.txt"])
    a.append(b) #a now has the same info as b
    a.append(b) #a now has ["hello.dat", "world.dat", "hello.dat", "world.dat"], ["foo.txt", "bar.txt", "foo.txt", "bar.txt"]
    

    The difference betweeen append and extend is this

    a = [1,2,3]
    b = [4,5,6]
    a.append(b) #a is now [1,2,3[4,5,6]]
    
    a = [1,2,3]
    b = [4,5,6]
    a.extend(b) #a is now [1,2,3,4,5,6]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 208k
  • Answers 208k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Donald Knuth says (The Art of Computer Programming, Third Ed.,… May 12, 2026 at 9:30 pm
  • Editorial Team
    Editorial Team added an answer That really depends on what procInEachDb does. I can understand… May 12, 2026 at 9:30 pm
  • Editorial Team
    Editorial Team added an answer This is possible, but isn't consistent across browsers. You can… May 12, 2026 at 9:30 pm

Related Questions

Possible Duplicate: Converting XML to JSON using Python? I am importing an XML feed
I've just started learning Emacs, and decided to start writing Python in it. I
I'm having a problem passing strings that exceed 80 characters in JSON. When I
I know next to nothing about SharePoint, so maybe this isn't something you can/should
First off, I know next to nothing about language theory, and I barely know

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.