1
def sort_domain():
    if self.cb1.isChecked():
        for line in f:
            line= line.strip()
            if line.endswith('.com') is True:
                self.textBrowser.append(line)
            else:
                pass
    elif not self.cb1.isChecked() and not self.cb2.isChecked():
        for line in f:
            line=line.strip()
            self.textBrowser.append(line)
    if self.cb2.isChecked():
        for line in f:
            line= line.strip()
            if line.endswith('.net') is True:
                self.textBrowser.append(line)
            else:
                pass
    elif not self.cb1.isChecked() and not self.cb2.isChecked():
        for line in f:
            line=line.strip()
            self.textBrowser.append(line)

self.btn2.clicked.connect(sort_domain)

If I checked cb1 and cb2 ((checkbox1 and chekbok2)) the results are all domains with extension .com only.

What is the correct way to write a function to show all Domains when you press the chekBox1 ".com" and chekBox2 ".net"?

code and window

tynn
  • 38,113
  • 8
  • 108
  • 143
drop22
  • 11
  • 4

1 Answers1

1

Your implementation is not really efficient: it reads the contents of the file more than once. And this is also the issue of your program. After the first for-loop the file object points to the end of the file and to make it work you'd have to seek to the start again: f.seek(0)

tynn
  • 38,113
  • 8
  • 108
  • 143