1

I've added another folder into my project so I can pull methods from files in another project. I did this with the first 3 lines

import sys
import os
sys.path.insert(0, '/path/to/another/dir')

from file_methods import load_object

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("path")
args = parser.parse_args()
print(args['path'])

When doing simple argparse, I'm getting the error:

Traceback (most recent call last):
  File "read_pupil_data.py", line 16, in <module>
    print(args['path'])
TypeError: 'Namespace' object is not subscriptable

How do I access this namespace?

1 Answer 1

3

There is no dictionary-like access to the parsed arguments. Use a dot notation (docs):

args = parser.parse_args()
print(args.path)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.