Python : getsize not defined
Question: I am trying to sort the files based on their size and store the log in a file.
But I get an error that says 'getsize' not defined. Please help me fix this.

    
    
    from ClientConfig import ClientConfig
    import os
    import os.path
    
    class VerifyFileNSize:
        def __init__(self):
            self.config = ClientConfig()
            self.parseInfo()
    
        def parseInfo(self):
            count = 0
            size = 0
            sort_file = []
            originalPath = os.getcwd()
            os.chdir(self.config.Root_Directory_Path())    
            log = open(self.config.File_Count(),'wb')        
            for root, dirs, files in os.walk("."):            
                for f in files:
                    sort_file.append(os.path.join(root, f))
    
            sorted_file = sorted(sort_file, key=getsize)
    
            for f in sorted_file:
                log.write((str(os.path.getsize(f)) + " Bytes" + "|" + f  +         os.linesep).encode())                
                size += os.path.getsize(f)
                count += 1
            totalPrint = ("Client: Root:" + self.config.Root_Directory_Path() + " Total     Files:" + str(count) + " Total Size in Bytes:" + str(size) + " Total Size in     MB:" + str(round(size /1024/1024, 2))).encode()
            print(totalPrint.decode())
            log.write(totalPrint)
            log.close()
            os.chdir(originalPath)
    
    if __name__ == "__main__":
        VerifyFileNSize()
    


Answer: Try prepending `os.path`:

    
    
    sorted_file = sorted(sort_file, key=os.path.getsize)
                                        ^^^^^^^^
    

Alternatively, you could just say `from os.path import getsize`.

