Note that there are some explanatory texts on larger screens.

plurals
  1. POPython use variable in f.write
    primarykey
    data
    text
    <p>I am trying to use <code>f.write</code> i am not sure its a best way to do but i saw couple of example. here what i am trying to do, I have a file which contain following lines.</p> <pre><code>parallel ( { ignore(FAILURE) { build( "Deploy", BUILDFILE: "/path/to/build.xml", WARFILE: "http://www.example.com/repo/file.war", STUDY: "EXAMPLE", BUG: "007" ) }}, </code></pre> <p>In above file you can see <code>BUILDFILE</code>, <code>WARFILE</code>, <code>STUDY</code> and <code>BUG</code> field. I want to to edit them using script in place of manually edit. I don't under stand how do i use variable in f.write() function. following what i am trying to do</p> <pre><code>BF = raw_input("Enter BUILDFILE name:") WF = raw_input("Enter WARFILE name:") STUDY = raw_input("Enter STUDY name:") BUG = raw_input("Enter BUG name:") f = open("myfile", "w") data = """parallel ( { ignore(FAILURE) { build( "Deploy", BUILDFILE: "BF", WARFILE: "WF", STUDY: "STUDY", BUG: "BUG" ) }}, f.write(data) f.close() </code></pre> <p>when i am running this code it take my input and put in those specified field but some how its not working.. i don't know how to use f.write to take my variable and place in those fields. if there is a another way please let me know.. </p> <p><strong>EDIT</strong></p> <p>I have modified script as per users suggested but still getting error, I am missing something ??? </p> <pre><code>#!/usr/bin/python import sys BF = raw_input("Enter BUILDFILE name:") WF = raw_input("Enter WARFILE name:") STUDY = raw_input("Enter STUDY name:") BUG = raw_input("Enter BUG name:") f = open("myfile", "w") data = """parallel ( { ignore(FAILURE) { build( "Deploy", BUILDFILE: "{BF}", WARFILE: "{WF}", STUDY: "{STUDY}", BUG: "{BUG}" ) }},""".format(**locals()) f.write(data) f.close() </code></pre> <p>following error i am getting</p> <pre><code>Traceback (most recent call last): File "./sched.py", line 18, in &lt;module&gt; }},""".format(**locals()) KeyError: '\nignore(FAILURE) {\n build( "Deploy", BUILDFILE' </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.
 

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