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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:28:08+00:00 2026-06-16T14:28:08+00:00

Possible Duplicate: Least Astonishment in Python: The Mutable Default Argument I’m using the MailSnake

  • 0

Possible Duplicate:
“Least Astonishment” in Python: The Mutable Default Argument

I’m using the MailSnake in Python, which is a wrapper for the MailChimp API.

Now I’m getting some curious behaviour for a function I’ve written to pull lists of subscribers we have. This is the code I’m using:

from mailsnake import MailSnake
from mailsnake.exceptions import *

ms = MailSnake('key here')

def return_members (status, list_id, members = [], start = 0, limit = 15000, done = 0):
    temp_list = ms.listMembers(status=status, id=list_id, start=page, limit=limit, since='2000-01-01 01:01:01')
    for item in temp_list['data']:  # Add latest pulled data to our list
        members.append(item)
    done = limit + done
    if done < temp_list['total']:  # Continue if we have yet to 
        start = start + 1
        if limit > (temp_list['total'] - done):  # Restrict how many more results we get out if are on the penultimate page
            limit = temp_list['total'] - done
        print 'Making another API call to get complete list'
        return_members(status, list_id, members, page, limit, done)
    return members

for id in lists:
    unsubs = return_members('subscribed',id)
    for person in unsubs:
        print person['email']

print 'Finished getting information'

So this function runs recursively until we have pulled all members from a given list.

But what I’ve noticed is that the variable unsubs seems to just get bigger and bigger. In that when the function return_members is called with different list ids, I get an amalgamation of the emails of every list I have called so far (rather than just one particular list).

If I call return_members(‘subscribed’, id, []) which explicitly gives it a fresh array then it’s fine. But I don’t see why I need to do this, as if I am calling the function with a different list ID, it’s not running recursively and since I haven’t specificed the members variable, it defaults to []

I think this may be a quirk of python, or I’ve just missed something!

  • 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-06-16T14:28:09+00:00Added an answer on June 16, 2026 at 2:28 pm

    The linked SO infamous question by Martjin would help you understand the underline issue, but to get this sorted out you can write the following loop

    for item in temp_list['data']:  # Add latest pulled data to our list
        members.append(item)
    

    to a more pythonic version

    members = members + temp_list['data'] # Add latest pulled data to our list
    

    this small change would ensure that you are working with an instance different from the one passed as the parameter to return_members

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

Sidebar

Related Questions

Possible Duplicate: Least Astonishment in Python: The Mutable Default Argument Python - Using the
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Using python 2.7 I
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm finding that dictionary
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm trying to create
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I was working on
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument def f(a, L=[]): L.append(a)
Possible Duplicate: least astonishment in python: the mutable default argument I want to understand
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm very confused about
Possible Duplicate: Least Astonishment in Python: The Mutable Default Argument from random import random
Possible Duplicate: Least Astonishment in Python: The Mutable Default Argument class Klass(object): def a(self,

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.