print(messageclass persondef __init__(selfnamejob=none)self name name self job job object factory(spammake spam object object factory(person"arthur""king"make person object object factory(personname='brian'dittowith keywords and default in this codewe define an object generator function called factory it expects to be passed class object (any class will doalong with one or more arguments for the class' constructor the function uses special "varargscall syntax to call the function and return an instance the rest of the example simply defines two classes and generates instances of both by passing them to the factory function and that' the only factory function you'll ever need to write in pythonit works for any class and any constructor arguments if you run this live (factory py)your objects will look like thisobject doit( object nameobject job ('arthur''king'object nameobject job ('brian'noneby nowyou should know that everything is "first classobject in python--including classeswhich are usually just compiler input in languages like +it' natural to pass them around this way as mentioned at the start of this part of the bookthoughonly objects derived from classes do full oop in python why factoriesso what good is the factory function (besides providing an excuse to illustrate firstclass class objects in this book)unfortunatelyit' difficult to show applications of this design pattern without listing much more code than we have space for here in generalthoughsuch factory might allow code to be insulated from the details of dynamically configured object construction for instancerecall the processor example presented in the abstract in and then again as composition example earlier in this it accepts reader and writer objects for processing arbitrary data streams the original version of this example manually passed in instances of specialized classes like filewriter and socketreader to customize the data streams being processedlaterwe passed in hardcoded filestreamand formatter objects in more dynamic scenarioexternal devices such as configuration files or guis might be used to configure the streams classes are objectsgeneric object factories