I need to write a program having a GUI to input a File - shtech1.txt Then need to open the file and extract lines between
- show vlan
and
- show
and write to another file - shvlan1.txt
Below is my program and I am getting error TypeError: can't use a string pattern on a bytes-like object
on the line:
if re.match('- show vlan -',line):
Could someone help me on this
Code:
def on_pushButton_clicked(self): #shtech1
dialog = QFileDialog(self)
dialog.exec_()
for file in dialog.selectedFiles():
shtech1 = QFile(file)
shtech1.open(QFile.ReadOnly)
found = False
copy = False
shvlan1 = open('shvlan1.txt', 'a')
while not found:
line = shtech1.readLine()
print("line is",line)
if re.match('- show vlan -',line):
copy = True
print ("copy is True")
elif re.match('- show',line):
if copy:
found = True
copy = False
print ("copy is False")
elif copy:
shvlan1.write(line)
print ("printing")
shvlan1.close()
shtech1.close()
Getting the below error:
File "UImlag.py", line 34, in on_pushButton_clicked
if re.match('- show vlan -',line):
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/re.py", line 160, in match
return _compile(pattern, flags).match(string)
TypeError: can't use a string pattern on a bytes-like object