Every good developer knows reusing code is essential to efficiency.  Most programmers maintain a set of core snippets used in the process of application development.  I decided to approach this a little differently in my Python learning process, by creating a framework to contain utility functions and classes that might be useful among projects.


At the core of the PokeyWorks framework is the PokeyConfig class.

You may have noticed the PokeyConfig class is pretty small.  It only has a few methods available –  load_config(), check_attr(), __str__(), __init__() . This is partly due to the intention to use the class as a collection of configuration attributes to be acted upon within your application’s primary execution.

The  self.load_config() method attempts to open and parse the file passed in the invocation of this class.  The file format can be adjusted by editing the list comprehension in the return statement :

As written, this will return a list comprised of lists of 3 values which are in tab-delimited format in the file.  It also ignores any row beginning with a hash # for commenting, or blank lines.

The contents of my config file for the PokeyHost application are :

Each configuration option value will become an attribute of the PokeyConfig class containing a list with two values – the value and description of that attribute.

In the example above, once loaded the Compression algorithm option would be accessed via the  PokeyConfig.comp attribute, with the value  PokeyConfig.comp[0] containing the value, and  PokeyConfig.comp[1] containing the description.

Used as a superclass

The PokeyConfig class is intended to be a superclass that could be applied in an application as in the following example.

In this example the  AppConfig class is a child class of the  PokeyConfig class, and would have access to all of its methods and attributes.  The file app.conf in the script executing directory is loaded and the AppConfig  class would contain all config attributes in this file.  Using a child class allows you to extend the class with custom  __init__ and other methods if desired, as your application requires.

More to come

The PokeyWorks framework contains many additional tools, including language parsing (word pluralization, grammar and vocabulary library support), ircBots (for integration with various messaging systems), file system operations (local module installation using easy_install, resource path detector), and much more.

Stay tuned for more in the PokeyWorks series.