Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have two decent options:</p> <ol> <li>Python standard config file format using <a href="http://docs.python.org/lib/module-ConfigParser.html" rel="noreferrer" title="ConfigParser">ConfigParser</a></li> <li><a href="http://www.yaml.org/" rel="noreferrer" title="YAML">YAML</a> using a library like <a href="http://pyyaml.org/" rel="noreferrer" title="PyYAML">PyYAML</a></li> </ol> <p>The standard Python configuration files look like INI files with <code>[sections]</code> and <code>key : value</code> or <code>key = value</code> pairs. The advantages to this format are:</p> <ul> <li>No third-party libraries necessary</li> <li>Simple, familiar file format.</li> </ul> <p>YAML is different in that it is designed to be a human friendly data serialization format rather than specifically designed for configuration. It is very readable and gives you a couple different ways to represent the same data. For your problem, you could create a YAML file that looks like this:</p> <pre><code>file .* does not exist : file not found user .* not found : authorization error </code></pre> <p>Or like this:</p> <pre><code>{ file .* does not exist: file not found, user .* not found: authorization error } </code></pre> <p>Using PyYAML couldn't be simpler:</p> <pre><code>import yaml errors = yaml.load(open('my.yaml')) </code></pre> <p>At this point <code>errors</code> is a Python dictionary with the expected format. YAML is capable of representing more than dictionaries: if you prefer a list of pairs, use this format:</p> <pre><code>- - file .* does not exist - file not found - - user .* not found - authorization error </code></pre> <p>Or</p> <pre><code>[ [file .* does not exist, file not found], [user .* not found, authorization error]] </code></pre> <p>Which will produce a list of lists when <code>yaml.load</code> is called.</p> <p>One advantage of YAML is that you could use it to export your existing, hard-coded data out to a file to create the initial version, rather than cut/paste plus a bunch of find/replace to get the data into the right format.</p> <p>The YAML format will take a little more time to get familiar with, but using PyYAML is even simpler than using ConfigParser with the advantage is that you have more options regarding how your data is represented using YAML.</p> <p>Either one sounds like it will fit your current needs, ConfigParser will be easier to start with while YAML gives you more flexibilty in the future, if your needs expand.</p> <p>Best of luck!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload