Expanding Dr.Rabbit's answer a little, what you want to do is actually run a shell command (
hostname -I), which returns the IP address of the machine running that command. As the Python script you're running is one process and the shell command is also another process, what you need to do from your Python script is
- run the shell command
- wait till it has run
- retrieve in a variable the text (the IP address) it has written to the subprocess' standard output, which you send to the display
and subprocess.check_output does exactly that. What popen does is only prepare a sub-process, which the calling script still needs to interact with hence the bizarre garbage text you noticed.
However note that
shell = True poses a security risk:
Warning : Using
shell=True can be a security hazard. See the warning under Frequently Used Arguments for details.
A safer approach would be to run command
hostname -I and clean up the returned text from within Python:
IP = subprocess.check_output(["hostname", "-I"]).split()
#send it to the LCD