[Python] When do I need to be careful if changing the directory?

Discussão em 'Python' iniciado por Stack, Maio 2, 2025.

  1. Stack

    Stack Membro Participativo

    Iam using os to get image files and PIL to open and compare them. Afterwards I want to store them in different directories whether they are the same or not.

    Do I have to be carful when using the following?

    os.walk()
    os.listdir()
    os.makedirs()
    Image.save()


    These concerns arose after reading change working directory, which is why Iam using the following code as recommended:

    from contextlib import chdir

    with chdir(path):
    # do stuff here


    Thank you alot for your answer, since Iam just learning python!

    Continue reading...

Compartilhe esta Página