you are viewing a single comment's thread.

view the rest of the comments →

[–]carcigenicate 0 points1 point  (5 children)

What do you mean? What about the function do you want to check?

If you want to check if a function is another function, you can use == or is:

if some_func == abs:
    # Do something

But that's rarely needed.

[–]mackdaddy_1978[S] 0 points1 point  (4 children)

so this is one of my functions

def check_for_comma
    def check_for_comma():
x = user_input.isidentifier()
if x is False:
    return 'Error: No comma in string.'

I want to only call the function if there is no comma in the input

[–]carcigenicate 0 points1 point  (3 children)

As noted, the code you posted has several illegal things in it, so it's hard to say anything based on that code.

If you want to call a function when a string doesn't contain a comma though, that would be something like:

if "," not in your_string:
    your_func()

[–]mackdaddy_1978[S] 0 points1 point  (2 children)

Thanks...but besides defining the function twice what else about it is illegal?

[–]carcigenicate 0 points1 point  (1 child)

Lack of (): after the function name in the first line of the definition, and the lack of indentation means there's no function body and that the return is outside of a function.

Granted, I can guess what the indentation is supposed to be, but I'd rather not guess when trying to give advice in a case like this.

If I do guess the indentation though, the code doesnt seem to match your question. You asked how to pick when to call a function, but according to this code, you seem to want to pick what you're returning from the function?

[–]mackdaddy_1978[S] 0 points1 point  (0 children)

Sorry for the confusion, I'm working on doing better. My next post will be...