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.
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.