driscollis / applications_with_wxpython

Code examples for the book, Creating GUI Application with wxPython
https://www.blog.pythonlibrary.org
116 stars 26 forks source link

Chapter 11 - search_threads.py - Duplicate code? #20

Closed cmcknight closed 5 years ago

cmcknight commented 5 years ago

I'm seeing the following code:

def run(self):
    start = time.time()
    for entry in os.scandir(self.folder):
        if entry.is_file():
            if self.case_sensitive:
                path = entry.path
            else:
                path = entry.path.lower()
             if self.search_term in path:
                _, ext = os.path.splitext(entry.path)
->                if self.file_type and self.file_type == ext.lower():
->                    data = (entry.path, entry.stat().st_mtime)
->                    wx.CallAfter(pub.sendMessage,
->                                 'update', result=data)
->                else:
->                    data = (entry.path, entry.stat().st_mtime)
->                    wx.CallAfter(pub.sendMessage,
->                                 'update', result=data)
    end = time.time()
    wx.CallAfter(pub.sendMessage, 'status', search_time=end-start)'

and I'm wondering what the purpose of the if/else statement serves. It appears that the same code is called regardless of whether the if or the else branch is executed.

driscollis commented 5 years ago

I'm pretty sure there was a difference while I was developing it and then as it got abstracted, the differences went away without me noticing. Sorry about that. I just removed the duped code and submitted it.