following some examples from https://www.programcreek.com/python/example/121/getopt.getopt where they make option comparisons with == i.e (option == "--json"), I am trying to enter the if statement. However option will not match despite being of type string and "--json". Can anyone see what is going wrong?
import sys, getopt
argv = sys.argv[1:]
def main(argv):
try:
opts, args = getopt.getopt(argv,'',['json ='])
except:
print("failed to get arguments")
for (option, value) in opts:
print(option)
print(type(option))
if str(option) == "--json":
print ("enters here")
main(argv)
$ python test.py --json data
--json
<class 'str'>