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 7032317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:55:09+00:00 2026-05-28T00:55:09+00:00

I maintain a project that has a function definition similar to this: def f(a,

  • 0

I maintain a project that has a function definition similar to this:

def f(a, (b1, b2), c):
    print locals()

While debugging the code I discovered that a .1 key appeared in locals(), with the value (b1, b2). A quick check revealed that a function definition like the following:

def f((a1, a2)):
    print locals()

will have a .0 key in locals() with the value (a1, a2). I was surprised by this behavior, but could find no information in the Python documentation.

My questions are: do these otherwise-inaccessible positional variables affect memory or performance? Are they documented anywhere? What purpose do they serve?

The project in question is feedparser, which is SAX-based and could potentially have dozens or hundreds of function calls that would be affected by this behavior.

  • 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-28T00:55:10+00:00Added an answer on May 28, 2026 at 12:55 am

    so pep 3113, as artur gaspar points out, contains a full answer. It also lists a whole bunch of reasons why this probably isn’t a great pattern to follow. One of these you discovered in the annoying side effects of debugging. A bigger one is I think that your code will break transitioning to python3, but I’m not sure/still am on 2.7 personally.

    I wanted to play with what happens. Looking as some disassembled bytecodes we can see what happens with these three functions (spoiler: foo and bar have identical bytecodes):

    from dis import dis
    
    def foo(a, (b, c) ,d):
        return a + b + c + d
    
    def bar(a, b_c, d):
        b, c = b_c
        return a + b + c + d
    
    def baz(a, b, c, d):
        return a + b + c + d
    
    print '\nfoo:'
    dis(foo)
    print '\nbar:'
    dis(bar)
    print '\nbaz:'
    dis(baz)
    

    Yields:

    foo:
      3           0 LOAD_FAST                1 (.1)
                  3 UNPACK_SEQUENCE          2
                  6 STORE_FAST               3 (b)
                  9 STORE_FAST               4 (c)
    
      4          12 LOAD_FAST                0 (a)
                 15 LOAD_FAST                3 (b)
                 18 BINARY_ADD          
                 19 LOAD_FAST                4 (c)
                 22 BINARY_ADD          
                 23 LOAD_FAST                2 (d)
                 26 BINARY_ADD          
                 27 RETURN_VALUE        
    
    
    bar:
      7           0 LOAD_FAST                1 (b_c)
                  3 UNPACK_SEQUENCE          2
                  6 STORE_FAST               3 (b)
                  9 STORE_FAST               4 (c)
    
      8          12 LOAD_FAST                0 (a)
                 15 LOAD_FAST                3 (b)
                 18 BINARY_ADD          
                 19 LOAD_FAST                4 (c)
                 22 BINARY_ADD          
                 23 LOAD_FAST                2 (d)
                 26 BINARY_ADD          
                 27 RETURN_VALUE        
    
    
    baz:
     11           0 LOAD_FAST                0 (a)
                  3 LOAD_FAST                1 (b)
                  6 BINARY_ADD          
                  7 LOAD_FAST                2 (c)
                 10 BINARY_ADD          
                 11 LOAD_FAST                3 (d)
                 14 BINARY_ADD          
                 15 RETURN_VALUE        
    

    As you can see. foo and bar are identical, while baz skips the unpacking. So yes, this will affect performance a bit, but only as long as tuple unpacking takes, which should be negligible in everything except very small functions and toy examples (like this one ;P)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I maintain a Django project with a database that has several model constraints that
There is a project that I need to maintain that talks to mysql via
By default, Eclipse won't show my .htaccess file that I maintain in my project.
I got a task to maintain a c# project, I found some code like
In a recent project, I have to maintain some PHP code. I set up
I'm in a situation where I've got a project that has a large number
I recently joined this organisation that I am currently working at that has asked
Over time, the code base I maintain has grown exponentially. We have a variety
I'm working on a desktop project using WPF, framework 3.5. This application has lots
Part of my project requires that we maintain stats of our customers products. More

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.