Get parameters when running a script from settings.xml
#1
I'm running my script from "settings.xml" and passing a parameter but I don't know how to access that parameter when the script is run.
Could someone point me to an example?

In settings.xml I have the following line.

xml:
​​​​​​<setting id="backup" type="action" label="Backup Database" action="RunScript(script.myscript,backup)"/>

It is running "script.myscript" but I just don't know how to tell if the "backup" parameter is set.

Any help is appreciated.
Reply
#2
Code:

if __name__ == '__main__':
    arg = None

    try:
       arg = sys.argv[1].lower()
    except Exception:
       pass

    if arg == "backup":
        backupFunction()
    elif arg == "restore":
        restoreFunction()
Reply
#3
Perfect!  Thanks so much!  Smile
Reply
#4
(2017-11-19, 13:27)DaLanik Wrote:
Code:

if __name__ == '__main__':
    arg = None

    try:
       arg = sys.argv[1].lower()
    except Exception:
       pass

    if arg == "backup":
        backupFunction()
    elif arg == "restore":
        restoreFunction()
 Don't ever catch bare Excepiton, unless you really know what you are doing. Always catch a specific exception type. If you are not sure if a list contains that many elements, then catch IndexError.
Reply
#5
(2017-11-19, 16:51)Roman_V_M Wrote:
(2017-11-19, 13:27)DaLanik Wrote:
Code:

if __name__ == '__main__':
    arg = None

    try:
       arg = sys.argv[1].lower()
    except Exception:
       pass

    if arg == "backup":
        backupFunction()
    elif arg == "restore":
        restoreFunction()
 Don't ever catch bare Excepiton, unless you really know what you are doing. Always catch a specific exception type. If you are not sure if a list contains that many elements, then catch IndexError
 I don't know WHAT to expect Smile I know it is best to catch specific exception, this is just in case Smile
Reply
#6
(2017-11-19, 17:57)DaLanik Wrote:  I don't know WHAT to expect Smile I know it is best to catch specific exception, this is just in case Smile

In that case you need to consult documentation or manuals. The rule of thumb is that try/except construction should be used only to catch known exception types that are raised under normal program work. Unexpected exceptions are signs of potential bugs and should be properly analyzed and addressed. Just swallowing them with bare except or except Exception leads to more serious bugs that are hard to find.
Reply

Logout Mark Read Team Forum Stats Members Help
Get parameters when running a script from settings.xml0