L
L
leham12020-05-14 19:47:28
Python
leham1, 2020-05-14 19:47:28

Why, when rearranging function arguments, do the arguments take on each other's values?

Why, when rearranging the name and path arguments in a function, they take on each other's values. Previously, I rearranged the named arguments in places and everything worked fine, but now some stupidity is happening.
so the code works:

def folder_bypass(path=r"C:\YandexDisk\товары\товаров фото", name='1466 ав213'):
    for i in os.listdir(path):
        if os.path.isdir(path + '\\' + i):
            folder_bypass(path + '\\' + i, name)
        if name == i:
            q1 = path + '\\' + i
            return q1

folder_bypass()


Такой код уже не работает:
<code lang="python">
def folder_bypass(name='1466 ав213', path=r"C:\YandexDisk\товары\товаров фото"):
    for i in os.listdir(path):
        if os.path.isdir(path + '\\' + i):
            folder_bypass(path + '\\' + i, name)
        if name == i:
            q1 = path + '\\' + i
            return q1

folder_bypass()
</code>

Эта ошибка выскакивает:
<code lang="python">
C:\Users\первый\AppData\Local\Programs\Python\Python38-32\python.exe C:/YandexDisk/бизнес/Python/proverkaSoobchenii/test_5.py
Traceback (most recent call last):
  File "C:/YandexDisk/бизнес/Python/proverkaSoobchenii/test_5.py", line 30, in <module>
    folder_bypass()
  File "C:/YandexDisk/бизнес/Python/proverkaSoobchenii/test_5.py", line 25, in folder_bypass
    folder_bypass(path + '\\' + i, name)
  File "C:/YandexDisk/бизнес/Python/proverkaSoobchenii/test_5.py", line 23, in folder_bypass
    for i in os.listdir(path):
FileNotFoundError: [WinError 3] Системе не удается найти указанный путь: '1466 авито213'
</code>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2020-05-14
@leham1

Because inside, on line 4, the first argument is set to path + ..., and the second to name. Swap them there, everything should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question