-2

I need some help to create a loop for my program. My problem is that I have to run the script twice, before the file/output registers any changes done to my configuration.

Programming is not my strongest skill - hope someone can be of assistance

UPDATED code:

try:
    rescue = cu.rescue(action="get", format="text")
    if rescue is None:
        print ("No existing rescue configuration.")
        print ("Saving rescue configuration.")
        cu.rescue(action="save")    
    else:
        print ("Rescue configuration exist:")
        print ("Updating rescue configuration")
        cu.rescue(action="save")
        print (rescue)
except Exception as err:
    print (err)

with open("Rescue Config.config", "w") as text_file:
text_file.write(rescue)
znoevil
  • 1
  • 2
  • 1
    Does it give indentation error? Or you have pasted the code without proper formatting? while using `with` you need not to close the file – mad_ Nov 06 '18 at 15:01
  • Its just pasted without proper formatting - Okay thanks – znoevil Nov 06 '18 at 15:11
  • If you're going to post Python code, please make an effort to reproduce your indentation accurately. If readers have to try and guess your actual indentation, they may miss problems or introduce new ones into the program. – khelwood Nov 06 '18 at 15:18

1 Answers1

1

indentation matters in python, change the last few lines of your code to this

with open("Rescue Config.config", "w") as text_file:
     text_file.write(rescue)

no need to close the file, this happens automatically when using the with statement

vencaslac
  • 2,727
  • 1
  • 18
  • 29