I am trying to use f.write
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.
parallel (
{
ignore(FAILURE) {
build( "Deploy", BUILDFILE: "/path/to/build.xml", WARFILE: "http://www.example.com/repo/file.war", STUDY: "EXAMPLE", BUG: "007" )
}},
In above file you can see BUILDFILE
, WARFILE
, STUDY
and BUG
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
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()
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..
EDIT
I have modified script as per users suggested but still getting error, I am missing something ???
#!/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()
following error i am getting
Traceback (most recent call last):
File "./sched.py", line 18, in <module>
}},""".format(**locals())
KeyError: '\nignore(FAILURE) {\n build( "Deploy", BUILDFILE'