I am a kind of a newbie in Python. I have multiple configuration files of cisco device in the same path and I want to check whether how many devices were configured Radius IP 10.10.10.4 but when I ran to a file, I found an error as below (problem on some files)
Traceback (most recent call last): File "D:/Test Python/Config file/testoslist.py", line 6, in if '10.10.10.4' in f.read(): File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\encodings\cp874.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 152485: character maps to
import os
import os.path
for fname in os.listdir('.'):
if os.path.isfile(fname):
f = open(fname)
if '10.10.10.4' in f.read():
print(fname)
f.close()
and If I want to write output to the new file how I can do?