title: how to apply factory pattern in python?
body: <p>i have a file reader class ( sample code below), defined a CHUNK_SIZE class member and a iterator function to read a data from a given file. I want to create objects of this class, based on a different chunk sizes, i was thiking of creating factory pattern or something similar, to create objects like in java or other languages . i created a factory class below, so that i can do something like myobj = get_file_reader(2048). does it makes sense to do this in python or does it have different convention or ways to do this. my idea is , if i need to add a specific file readers say, csv_reader or text_reader or image_reader, it can inherit from my file_reader class?</p>
  <p>factory class</p>
  <pre><code>class File_Reader_Factory {
      def get_File_Reader(size)
        if size == null:
            throw valueerror ; 
           
        else: 
           return File_Reader(size);
  
  </code></pre>
  <pre><code>class File_Reader:
     def __init__(self, chunk_size):
        #initialize code
        CHUNK_SIZE = chunk_size
  
     def read_file_chunks(file_object):
         &quot;&quot;&quot;Lazy function (generator) to read a file piece by piece.
         while True:
             data = file_object.read(CHUNK_SIZE)
             if not data:
                 break
             yield data
  </code></pre>