Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Address object #26

Open
philhy opened this issue Dec 11, 2023 · 0 comments
Open

Issues with Address object #26

philhy opened this issue Dec 11, 2023 · 0 comments

Comments

@philhy
Copy link

philhy commented Dec 11, 2023

When trying to create multiple routes using a loop, I encountered the issue of the addresses from the previous iteration still being in the addresses variable. In address.py I believe I found the issue. Below is the current version of the code.

image

The issue here is that the addresses parameter is assigned a kwarg of an empty list. However, in python using a mutable object such as a list as a kwarg means that whenever the function is called the changes made to that parameter are stored in the function itself, thereby effecting the output every time the function is called. In this case, every time you create an Address object the addresses are stored in the addresses list and are not removed when you create another Address object. This can be avoided by either re-running the .py file if you're in an IDE or restarting the kernel if you're in Jupyter Notebook. However, making a simple adjustment in the source code will allow you to run the function multiple times and have the list of addresses update every time the function is called.

image

Here, instead of assigning a list to the address parameter, we assign it a None value and create the empty list variable inside the function itself. This way every time an Address object is created the addresses list will clear itself out before adding the new addresses.

Hope anyone who had the same trouble finds this method useful, and feel free to correct any mistakes in my explanation or provide an even simpler solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant