← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #679113]: showMonitors() – what does "None" mean?

 

Question #679113 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/679113

Rainer posted a new comment:
Just did some further testing.

As RaiMan already noted, showMonitors() by itself does not produce the "None".
The "None" in my case resulted from calling showMonitors() from within a print() function.

The strange behavior here seems to be that the print() function in
general does not print a "None" (or whatever) return value.

This is independent of the "content" that shall be printed:

The following code:

print("WTF?")

… just prints the text and no subsequent "None".

The following code:

def func():
    return "WTF?"
print(func())

… just prints the text and no "None".

The following code (executing a print() in the called function:

def func():
    print("WTF?")
func()

… also just prints the text.

But the following code:

def func():
    print("WTF?")
print(func())

… prints the text plus a subsequent "None". Obviously the "inner"
print() function causes the called func() function to return "None",
which is then printed from the "outer" print().

To check that: The following code:

def func():
    print("WTF?")
    return 2
print(func())

… prints the text and then the "2".

The following code results in an error:

def func():
    result = print("WTF?")
    return result
printfunc())

… [error] script [ Untitled ] stopped with error in line 2 at column 13
… [error] SyntaxError ( "no viable alternative at input 'print'", )

print() seems to provide a return value, which cannot be assigned, but
is returned anyway to a calling "outer" function …

Astonishingly (or not?) the following code:

result = showMonitors()
print(result)

… prints the Monitor configuration PLUS the "None"!

Even if a put a str() in between to "isolate" the result varable from
the fact that the assigned value comes from a function:

result = str(showMonitors())
print(result)

… I get the additional "None" …

The following code:

result = "WTF?"
print(result)

… just prints the text, as expected.

Not sure whether this is really consistent … why does the print()
function think that the result variable contains the output of
showMonitors() if already the output of this function is explicitly
converted to a string before being assigned to the result variable in
the first place? And there is no called function involved and no
previous print() in the code that could result in "None" being returned
to wherever …

BTW:  I tried all printing with "print" as a "classic" Python 2
statement and as a Python 3 function, this had no influence.

All this is of course not really important, just somewhat fascinating …

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.