naming objects from string

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

    #16
    Re: naming objects from string


    "James Stroud" <jstroud@mbi.uc la.eduwrote in message
    news:zvoQg.3828 $e66.1118@newss vr13.news.prodi gy.com...
    Depends on your namespace, but for the local namespace, you can use this:
    >
    pya = object()
    pya
    <object object at 0x40077478>
    pylocals()['bob'] = a
    pybob
    <object object at 0x40077478>
    If you put this code within a function, it probably will not work.
    locals() is usually a *copy* of the local namespace and writes do not write
    back to the namespace itself.

    tjr



    Comment

    • Roberto Bonvallet

      #17
      Re: naming objects from string

      manstey wrote:
      [...]
      bob_apple=()
      bob_orange=()
      ..
      pete_red=()
      >
      I then populate the 9 tuples with data [...]
      You cannot "populate" a tuple. If you want to insert the values
      individually, you have to use a list. If you insert them all together,
      like this: bob_apple = (1, 2, ..., 9), you don't need to initialize
      bob_apple with an empty tuple.

      --
      Roberto Bonvallet

      Comment

      Working...