Skip to main content
Solved

How to stop a workbench with a Startup Python Script


I'm trying to write a Python-Script how tested a Published Parameter. If its FALSE it should stop the Workbench.

________________________________

import fme

 

pw = fme.macroValues['passwort']

 

if pw == "test":

 

print("PASSWORT RICHTIG")

 

else:

 

print("PASSWORT FALSCH")

___________________________

 

Best answer by jdh

Raise an exception.

 

 

ex.

 

 

raise ValueError('Password incorrect')
View original
Did this help you find an answer to your question?

5 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • Best Answer
  • April 13, 2016

Raise an exception.

 

 

ex.

 

 

raise ValueError('Password incorrect')

  • Author
  • April 13, 2016

hey jdh, thx for the answer.

I try it with the ASSERT statement.

And it works!!

FME_BEGIN_PYTHON script returned error on execution.

_____________________________________

import fme

 

pw = fme.macroValues['passwort']

 

assert pw == "test", "PASSWORT FALSCH"

____________________________________


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • April 13, 2016
theinzmann wrote:

hey jdh, thx for the answer.

I try it with the ASSERT statement.

And it works!!

FME_BEGIN_PYTHON script returned error on execution.

_____________________________________

import fme

 

pw = fme.macroValues['passwort']

 

assert pw == "test", "PASSWORT FALSCH"

____________________________________

Assertions are generally used for testing/debugging purposes, but essentially it's a shortcut for

 

if not (x): raise AssertionError (y)

mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • April 13, 2016

The example I have is

import os
if os.path.exists(outputFilename):
    raiseException("The output file already exists - choose a different destination filename.)

See this article for more info


jordimonk
mark2atsafe wrote:

The example I have is

import os
if os.path.exists(outputFilename):
    raiseException("The output file already exists - choose a different destination filename.)

See this article for more info

There needs to be an space between 'raise' and 'Exception' as in:

 

raise Exception("This is an exception")

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings