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

  • Home
  • SEARCH
  • 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 1041681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:23:25+00:00 2026-05-16T15:23:25+00:00

Python newbie here: I’m writing a market simulation in Python using Pysage, and want

  • 0

Python newbie here:

I’m writing a market simulation in Python using Pysage, and want to generate an arbitrary number of agents (either buyers or sellers) using the mgr.register_actor() function, as follows:

for name, maxValuation, endowment, id in xrange(5):
    mgr.register_actor(Buyer(name="buyer001", maxValuation=100, endowment=500),"buyer001")
    update name, maxValuation, endowment, id

What is a succinct, pythonic way to run that function call so that, each time the loop is run, the values of name, maxValuation, endowment, and id are changed, e.g. to name="buyer002", name="buyer003"...; maxValuation=95, maxValuation=90...; endowment=450, endowment=400...; "buyer002", "buyer003"... and so on.

I have tried different for-loops and list comprehensions, but haven’t found a way yet to dynamically update the function arguments without running into type issues.

Thanks in advance!

  • 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-16T15:23:26+00:00Added an answer on May 16, 2026 at 3:23 pm

    You can prepare the names, maxValuations, and endowments as lists (or iterators), then use zip to group corresponding elements together:

    names=['buyer{i:0>3d}'.format(i=i) for i in range(1,6)]
    maxValuations=range(100,75,-5)
    endowments=range(500,250,-50)
    for name, maxValuation, endowment in zip(names,maxValuations,endowments):
        mgr.register_actor(
            Buyer(name=name, maxValuation=maxValuation, endowment=endowment),name)
    

    Regarding the format string, '{i:0>3d}':

    I refer to this “cheat sheet” when I need to build a format string:

    http://docs.python.org/library/string.html#format-string-syntax
    replacement_field ::= "{" field_name ["!" conversion] [":" format_spec] "}"
    field_name        ::= (identifier|integer)("."attribute_name|"["element_index"]")* 
    attribute_name    ::= identifier
    element_index     ::= integer
    conversion        ::= "r" | "s"
    format_spec       ::= [[fill]align][sign][#][0][width][.precision][type]
    fill              ::= <a character other than '}'>
    align             ::= "<" | ">" | "=" | "^"
                          "=" forces the padding to be placed after the sign (if any)
                              but before the digits. (for numeric types)
    sign              ::= "+" | "-" | " "
                          " " places a leading space for positive numbers
    width             ::= integer
    precision         ::= integer
    type              ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" |
                          "o" | "x" | "X" | "%"
    

    So, it breaks down like this:

       field_name 
      /
    {i:0>3d}
        \\\\
         \\\`-type ("d" means integer)
          \\`-width 
           \`-alignment (">" means right adjust)
            `-fill character
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python newbie here. I'm writing a script that can dump some output to either
python newbie here. I'm writing the code to control an experiment that has multiple
I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here .
Python newbie here. I was trying to troubleshoot an issue with writing a csv
newbie python programmer here. I have written a script and want to modify the
I'm a python newbie and starting out with using the Bottle web framework on
As a newbie to Python, and mainly having a background of writing scripts for
I am a newbie in Python. I try to work with server using Thrift
Python newbie here and wanted to know if there was a way to combine
I am a Python newbie. I have this small problem. I want to print

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.