I have the following problem with the following Python code:
katalog = open(r"Katalog.txt", 'r')
katentrylist = open(r"katentrylist.txt", 'r')
for line in katalog:
for element in katentrylist:
if element in line:
print(element)
if clean6.search(element) != None:
element = clean6.sub('', element)
if clean7.search(element) != None:
element = clean7.sub('', element)
if clean8.search(element) != None:
element = clean8.sub('', element)
if clean9.search(element) != None:
element = clean9.sub('', element)
elementtxt = element + '.txt'
with open(elementtxt, 'a') as d:
d.writelines(line)
d.close()
elementtxt = ''
check = ''
When I try to execute the print(element) statement the variable element is empty after the if-Statement using the in operator. It is however possible for me to do a print-statement of the line variable or to print a random string. If I use any other if-statement which is true, not using the in operator it is also possible for me to print the element varibale.
Does someone have an explanation for this behavior and can give me a hint why this happens.
Thanks a lot!
Aucun commentaire:
Enregistrer un commentaire