New PokeyConfig Release!

In an effort to get away from custom-derived formats, I’ve retired legacy delimited files in favor of more universal JSON and YAML formats (either one!).  This will require the PyYaml module to be added in most cases.  Using pip :

The feature list for the next major release will include some sort of dependency management.

The new PokeyConfig class has several functions added to accommodate these formats and convert applications built in the old style:

  • load_config(self,conf_type,inpath=None) : called by the  __init__() method, this loads the file specified by the  fpath parameter and processes according to the file extension, either loading JSON or YAML formatted configuration information into the dictionary  PokeyConfig.conf_dict
  • convert_delimited(self,inpath,out_type) : this method is invoked by  load_config if a legacy PokeyConfig format is detected (with a delimiter passed to the function, or with the old .conf file extension).  The user is first prompted to select whether to convert to [J]SON, or [Y]AML.  Any input other than [JjYy] returns an [*] Invalid Choice error message and the user is prompted again.  The legacy file is read using  load_delimited , and that configuration dictionary is written to the file format of the user’s choice, with the same file name as inpath and an appropriate extension.  The same file is then read as verification, and the result compared to the existing dictionary.  Mismatches are reprocessed, raising an error the second iteration.
  • load_delimited(self,inpath,delimiter=',') : loads the passed  inpath and reads the data, splitting (by delimiter ) each line that does not start with a # or is blank and adding a dictionary entry for each configuration setting.  This function is intended for conversion operations, but could be used to force legacy reading of delimited files.  There is no delimited-write support, use the csv operations in PokeyWorks.
  • write_config(self,params=False,**kw)  : this function writes the current configuration state.  If the configuration has been applied as instance attributes, the current instance attribute values will replace the existing conf_dict values.
  • Full class
  • Example File Conversion


The new class usage offers flexibility in converting from one format to another, and automatic conversion of legacy delimited files.  The class is invoked with  __init__ :

If using the default JSON format, you simply need to pass a file path and the loaded options will be stored in the dictionary  PokeyConfig.conf_dict .  If auto_apply is True, the dictionary keys will be set as attributes as well.  Once the configuration is applied to the class instance, any call to  PokeyConfig.write_config will overwrite the values in configuration dictionary with the attribute values before writing to the file.

This optional “application” of the values allows the configuration to be confined to a single dictionary and edited in place, or applied as attributes of the class instance and accessible via dot referencing.  Example invocations of each method follow.

Example Conversion (Command-Line Interpreter):


Leave a Reply

Your email address will not be published. Required fields are marked *