Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since your property names have some internal structure to them, you might try using pyparsing to process your properties file:</p> <pre><code>from pyparsing import Word, alphas, alphanums, delimitedList, restOfLine props = """ projectName.ClusterNameServer1.sslport=443 projectName.ClusterNameServer1.port=80 projectName.ClusterNameServer1.host=myHostA projectName.ClusterNameServer2.sslport=443 projectName.ClusterNameServer2.port=80 projectName.ClusterNameServer2.host=myHostB """ # define format of a single property definition line ident = Word(alphas, alphanums+'_') propertyName = delimitedList(ident,'.') propertyDefn = propertyName("name") + '=' + restOfLine("value") # sample code that parses the properties and accesses the # name and value fields for prop in propertyDefn.searchString(props): print '.'.join(prop.name), '-&gt;', prop.value </code></pre> <p>Prints:</p> <pre><code>projectName.ClusterNameServer1.sslport -&gt; 443 projectName.ClusterNameServer1.port -&gt; 80 projectName.ClusterNameServer1.host -&gt; myHostA projectName.ClusterNameServer2.sslport -&gt; 443 projectName.ClusterNameServer2.port -&gt; 80 projectName.ClusterNameServer2.host -&gt; myHostB </code></pre> <p>If you can rely on the project-server-parameter structure of the properties, you can build a hierarchical object using defaultdicts (from the collections module):</p> <pre><code># use defaultdicts to accumulate these values into a nested structure from collections import defaultdict properties = defaultdict(lambda:defaultdict(dict)) # build hierarchical property structure # (assumes very rigid project-server-parameter naming) for prop in propertyDefn.searchString(props): properties[prop.name[0]][prop.name[1]][prop.name[2]] = prop.value # show data in nice outline form for project in properties: print '-', project for cluster in properties[project]: print ' -', cluster for param in properties[project][cluster]: print ' -', param, properties[project][cluster][param] </code></pre> <p>Prints:</p> <pre><code>- projectName - ClusterNameServer1 - host myHostA - sslport 443 - port 80 - ClusterNameServer2 - host myHostB - sslport 443 - port 80 </code></pre>
    singulars
    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. This table or related slice is empty.
    1. 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