2

Не могу понять что не так в этом коде, os.makedirs создает 1 папку, а 2ую отказывается по не понятной мне причине, подскажите пожалуйста.

import os

class Newclass :
    intstring = 1;
    def mainfunc(self, a, b):
        print(a)
        print(b)
        if os.path.exists(a) and os.path.exists(b): 
            print ("OK...")
        else: 
            print ("Creating Dirs...")
            if os.makedirs(a) and os.makedirs(b):
                print ("MakeDirs - OK")
            else:
                print ("MakeDirs - Error")





A = Newclass()
A.mainfunc("/home/pc/1", "/home/pc/2")

1 ответ 1

3

os.makedirs возвращает None в случае успеха (в случае ошибки вызывает исключение), поэтому второй вызов в if os.makedirs(a) and os.makedirs(b): уже не происходит и директория /home/pc/2 не создается.

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.