[Python] Updating an Imported Object

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose file_A.py is written as so:

    #file_A.py

    my_object = create_new_object()

    def update_object():
    global my_object
    my_object = update(my_object)


    and then in file_B.py we do as so:

    #file_B.py

    from file_A import my_object, update_object

    def process_object(object):
    #do some operation ...


    process_object(my_object) #first call to process_object()
    update_object()
    process_object(my_object) #second call to process_object()


    My question is, when the second call to process_object() is made, will it use the original version of my_object ,which is imported at the top of file_B.py, be used, or will it use the updated version which replaces my_object when the update_object() function is called from file_B.py?

    Continue reading...

Compartilhe esta Página