pirulo pirulo - 1 month ago 6
Python Question

formatting variables in Python

I'm having issues formatting my variables. My PORT1 and PORT2 are not working properly. I'm getting syntax errors. What I'm doing wrong. Thank you for the inputs.

import socket
import os
import netifaces
NICS = netifaces.interfaces()
PORT1 = NICS[1]
PORT2 = NICS[2]
os.system("nmcli con add type team-slave con-name team0-port1 ifname {}".format(PORT1)) master team0)
os.system("nmcli con add type team-slave con-name team0-port2 ifname {}".format(PORT2)) master team0)


Error:

os.system("nmcli con add type team-slave con-name team0-port1 ifname {}".format(PORT1)) + master team0)
^
SyntaxError: invalid syntax

Answer

Your problem that you are trying to append string master team0 but you didn't wrap that in quotes also there one more closing bracket than opening ones

I thin this is what it should be

os.system("nmcli con add type team-slave con-name team0-port1 ifname {} master team0".format(PORT1))
Comments