Infinite for loop

i am using a set of for loops to update directories to all of their directories, but it has entered a infinite loop and i dont know why.

Attr7 = Attr4
Attr4 = []
print("3")
for Attr8 in Attr7:
    print("new")
    for Attr9 in dir(Key1 + "." + Attr8):
        print(Attr9)
        print("5")
        Attr4.append(Attr8 + "." + Attr9)
print("end")

if i enter a single directory it prints “new” every cycle but never prints “end”.

This cannot be your code. You use Attr4 before it is defined. If I swap
the first 2 statements, Attr7 would be an empty list and the outer
for-loop would iterate zero times, terminating immediately and newer
printing “new” at all. Key1 is used but never defined.

Please post the actual code which exhibits your problem.

Cheers,
Cameron Simpson cs@cskk.id.au

you set Attr4 to whatever the directory you want to search is

You showed your code, which is good. But it is not a self-contained example,

I copied your code into a file sdir.py and put the code into a function:

def ffind(Attr4):

    Attr7 = Attr4
    Attr4 = []
    print("3")
    for Attr8 in Attr7:
        print(Attr8)
        for Attr9 in dir(Key1 + "." + Attr8):
            print(Attr9)
            Attr4.append(Attr8 + "." + Attr9)
    print("end")
    return Attr4

This makes testing easier. Started a Python repl and typed:

>>> from sdir import ffind
>>> ffind("venv")
3
v
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mennoh/python/test1/sdir.py", line 8, in ffind
    for Attr9 in dir(Key1 + "." + Attr8):
NameError: name 'Key1' is not defined
>>> ffind(["venv"])
3
venv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mennoh/python/test1/sdir.py", line 8, in ffind
    for Attr9 in dir(Key1 + "." + Attr8):
NameError: name 'Key1' is not defined

As you see I first tried this

That seemed rather unlikely to be right, so I tried with a one element list, which returned the same problem.

Please test the code you are sharing here, so we do not have to guess what it should have been.

key1 is the file you are in so “sdir” and Attr4 is the directory of what you want to search

Thanks @Mholscher . You did great job.