1

I've been learning to develop something using a Raspberry Pi 3. As it is obvious that python is generally used, I'm going with it too. I was learning using a code from pyimagesearch blog and I came up with some problem.

parser= argparse.ArgumentParser()

parser.add_argument("-c","--conf",required=True, help="Path to configuration file")



warnings.filterwarnings("ignore")

conf= json.load(open(args["conf"]))

I get there errors.

Traceback (most recent call last):
  File "surveillance_system.py", line 29, in <module>
    conf= json.load(open(args["conf"]))
NameError: name 'args' is not defined

So, I defined 'args' as follows before the json.load() line

args = vars(parser.parse_args())

Now, these errors

Traceback (most recent call last):
  File "surveillance_system.py", line 29, in <module>
    conf= json.load(open(args["conf"]))
  File "/usr/lib/python2.7/json/__init__.py", line 290, in load
    **kw)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 14 column 2 (char 264)

So need some help. I am new to python btw. Thank you.

mponagandla
  • 137
  • 13

1 Answers1

0

Personally, I don't know anything about argparse, so I would recommend you using getopt. Put

import sys

and

import getopt

if you don't already have these there, and then, the rest of your code would then look like this:

try:
   opts, args = getopt.getopt(sys.argv[1:],"c:",["conf="])
except getopt.GetoptError:
   print("Getopt error")
   sys.exit(1)
for opt, arg in opts:
    if opt in ("-c","--conf"):
        conf = json.load(open(arg))

Hope this will do the work

Adrijaned
  • 430
  • 6
  • 13
  • Hey Adrian, I'm sorry. I forgot to post. Actually, the problem was in json. I forgot a comma(,) after one keyword. Anyways thanks for your help man. – mponagandla May 29 '17 at 22:55