Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the file is in <a href="https://secure.wikimedia.org/wikipedia/en/wiki/.properties" rel="nofollow"><code>java.util.Properties</code></a> format then you could use <a href="https://bitbucket.org/jnoller/pyjavaproperties" rel="nofollow"><code>pyjavaproperties</code></a>:</p> <pre><code>from pyjavaproperties import Properties p = Properties() p.load(open('input.properties')) for name, value in [('ENABLEPRINTER', 'y'), ('PRINTERLIST', 'PRNT3')]: p[name] = value p.store(open('output.properties', 'w')) </code></pre> <p>It is not very robust, but various fixes for it could benefit people who come next.</p> <hr> <p>To replace multiple times in a short string:</p> <pre><code>for old, new in [('ENABLEPRINTER', 'y'), ('PRINTERLIST', 'PRNT3')]: some_string = some_string.replace(old, new) </code></pre> <p>To replace variables names in a configuration file (using <a href="http://www.voidspace.org.uk/python/configobj.html" rel="nofollow"><code>configobj</code> module</a>):</p> <pre><code>import configobj conf = configobj.ConfigObj('test.conf') for old, new in [('ENABLEPRINTER', 'y'), ('PRINTERLIST', 'PRNT3')]: conf[new] = conf[old] del conf[old] conf.write() </code></pre> <p>If by <code>replace('ENABLEPRINTER', 'y')</code> you mean assign <code>y</code> to the <code>ENABLEPRINTER</code> variable then:</p> <pre><code>import configobj ENCODING='utf-8' conf = configobj.ConfigObj('test.conf', raise_errors=True, file_error=True, # don't create file if it doesn't exist encoding=ENCODING, # used to read/write file default_encoding=ENCODING) # str -&gt; unicode internally (useful on Python2.x) conf.update(dict(ENABLEPRINTER='y', PRINTERLIST='PRNT3')) conf.write() </code></pre> <hr> <p>It seems <code>configobj</code> is not compatible with:</p> <pre><code>name = '.'something </code></pre> <p>You could quote it:</p> <pre><code>name = "'.'something" </code></pre> <p>Or:</p> <pre><code>name = '.something' </code></pre> <p>Or</p> <pre><code>name = .something </code></pre> <hr> <p><code>conf.update()</code> does something similar to:</p> <pre><code>for name, value in [('ENABLEPRINTER', 'y'), ('PRINTERLIST', 'PRNT3')]: conf[name] = value </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.
    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