So, this is the code I've got difficulties with:
import optarse
import subprocess
def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i", dest="interface")
parser.add_option("-m", dest="new_mac")
(options, arguments) = parser.parse_args()
def change_mac(interface, new_mac):
subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
change.mac(options.interface, options.new_mac)
As far as I know, the variables options & arguments are storing the values of whatever parser.parse_args() returns. Now, whenever I call this program in my terminal, it's giving me an error. It's saying that the name options is not defined. How is this possible?
PS: I know the solution is to work with return parser.parse_args()
, but I'm just trying to understand why the (options, arguments) = parser.parse_args()
doesn't work.
Thanks in advance!