Python give null-value if argument doesn't work

Hey Guys,

I have this little bit of python code where i try to create a surface.byperimeterpoints. I want to make it that the code gives a null-value when the argument is not eligible, like the Function Apply method in the picture. Can somebody help me out on how to solve this problem in Python?

Hi,
can you show the error?
Note:
the method need a list as argument

image

Hi,
I’m willfully puting in a wrong input. I want it to give a null value without the warning if the argument is not valid.

This is generally bad coding practice, but fits in a few niche conditions.

You’ll need to proceed your action with a try statement, and then provide the except statement.

Something like this:

try:
    outcome = Surface.ByPerimeterPoints(points)
except:
    outcome = None

The reason this is bad practice is that you are concealing the issue from your end users. There is a problem, they won’t find it without reverse engineering your entire code base.

A better solution would be to provide the exception rather then the null. This can be done by modifying the except portion of the code to be something like this:

except:
    Import traceback
    outcome = traceback.formatexec()
2 Likes

Thank you very much for the advice and help!

1 Like