# Reload a list using append

**URL:** <https://discuss.python.org/t/reload-a-list-using-append/59664>\
**Category:** Python Help\
**Created:** [July 31, 2024, 9:05pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664 "2024-07-31T21:05:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jctech2025](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jctech2025](https://discuss.python.org/u/jctech2025)\
**Post date:** [July 31, 2024, 9:05pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/1 "2024-07-31T21:05:05Z")

</div>

Hi all,

I’m using append to create multiple options to choose to run. I put print and it prints the list. What I’m trying to do is reload the list itself after the option has been chosen. Is there any way to do this?

Thanks

---

<div class="post-metadata">

**Author:** ![doomsdaychicken](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/doomsdaychicken/32/21525_2.png) [@doomsdaychicken](https://discuss.python.org/u/doomsdaychicken)\
**Post date:** [July 31, 2024, 9:12pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/2 "2024-07-31T21:12:43Z")

</div>

Can you share the relevant code? Unclear what you mean by ‘reload’ but perhaps the code will make it clearer

---

<div class="post-metadata">

**Author:** ![jctech2025](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jctech2025](https://discuss.python.org/u/jctech2025)\
**Post date:** [August 1, 2024, 3:46pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/3 "2024-08-01T15:46:12Z")

</div>

Oh yeah sorry! I wrote the question in a hurray before end of the day. Here is a paraphrase of the code:

\\  
mylist =   
mylist.append("Main Banner: ")  
mylist.append(“1. Option 1”)  
mylist.append(“2. Optiion 2”)

print(mylist[0])  
print(mylist[1])  
print(mylist[2])  
print(“”)

Option = input("Choose option above: ")

if Option == 1:

////

If the user chooses option 1, the actual command runs and finishes with exit code zero. But after that nothing, so I’m trying to make it reload the menu itself, hopefully.

Thanks

---

<div class="post-metadata">

**Author:** ![doomsdaychicken](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/doomsdaychicken/32/21525_2.png) [@doomsdaychicken](https://discuss.python.org/u/doomsdaychicken)\
**Post date:** [August 1, 2024, 4:56pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/4 "2024-08-01T16:56:02Z")

</div>

You could add a `while` loop around all this, so it keeps looping until the user selects the “Exit” option.

---

<div class="post-metadata">

**Author:** ![onePythonUser](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/onepythonuser/32/19158_2.png) [@onePythonUser](https://discuss.python.org/u/onePythonUser)\
**Post date:** [August 1, 2024, 6:45pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/5 "2024-08-01T18:45:20Z")

</div>

Hi,

formatting your code improves readability.

 ![format_code](https://us1.discourse-cdn.com/flex002/uploads/python1/original/3X/4/7/47da35e13c6136076b8ba3d504e18d99efc38ef0.png)

You can try something like the following script. You define the functions that you want to run per the available menu options. You then create a dictionary where you associate each function to a corresponding string menu option.

> [@jctech2025](#):
>
> I’m trying to do is reload the list itself after the option has been chosen.

As stated by the previous user, you enter the code inside a `while` loop. This will keep displaying the menu option after every selection. If the user wants to exit, they can just enter the associated string to exit. I have written it with the string input `Leave` for simplicity, but you can change it to whatever you’d like.

```python
# Define functions for the menu options
def opt_1():
    print('\n* Running option 1 ... *')

def opt_2():
    print('\n* Running option 2 ... *')

# Associate menu option with corresponding function 
mylist = {'Option 1': opt_1, 'Option 2': opt_2}

while True:

    # Options list:
    print('\nMain Banner')
    print('1. Option 1')
    print('2. Option 2\n')

    Option = input("Choose option above: ")

    if Option == 'Leave':
        print('\nExiting the program ...')
        break
    else:
        mylist[Option]()

```

By the way, if you would like to add additional menu options to the menu, you can do so like this:

```python
# Define new function to add
def opt_3():
    print('\n* Running option 3 ... *')

mylist['Option 3'] = opt_3 # Add additional option to the menu

```

---

<div class="post-metadata">

**Author:** ![jctech2025](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jctech2025](https://discuss.python.org/u/jctech2025)\
**Post date:** [August 1, 2024, 9:01pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/6 "2024-08-01T21:01:25Z")

</div>

Thank you for the input. I’m going to go through it. I don’t do much Python in my role, and it’s hard to make time each day, though I want to learn it better. Still glad I found this community. I’ll update soon.

---

<div class="post-metadata">

**Author:** ![jctech2025](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jctech2025](https://discuss.python.org/u/jctech2025)\
**Post date:** [August 1, 2024, 10:17pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/7 "2024-08-01T22:17:01Z")

</div>

I did what you suggested and it worked! I was missing a command, I think I saw the while True before but didn’t try it. Thank You. Working on a basic desktop tool but in python. Starting with nslookup and testing port connectivity to the destination IP. Once I get nslookup working it’s a start. Did the same type of project in powershell so working to create in Python. Stuff is not easy.

---

<div class="post-metadata">

**Author:** ![onePythonUser](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/onepythonuser/32/19158_2.png) [@onePythonUser](https://discuss.python.org/u/onePythonUser)\
**Post date:** [August 1, 2024, 11:07pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/8 "2024-08-01T23:07:34Z")

</div>

> [@jctech2025](#):
>
> Stuff is not easy

Hang in there. You’re doing just fine. The more you learn, the more interesting and fun it gets as you can create more interested projects. By the way, I forgot to include the `Leave` option as part of a menu option in the printed list. You should include that option as well; i.e., `print("3. Enter 'Leave' to exit.")`, as an example.

---

<div class="post-metadata">

**Author:** ![jctech2025](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jctech2025](https://discuss.python.org/u/jctech2025)\
**Post date:** [August 2, 2024, 6:44pm UTC](https://discuss.python.org/t/reload-a-list-using-append/59664/9 "2024-08-02T18:44:17Z")

</div>

Thank you I appreciate that. I got into the code realm if you will, with Powershell. I’m no expert in that either but I didn’t want to be bound to only that. Usually my questions to the community are me trying to take the PS picture and put it into Python is that makes sense. Thanks again!
