I am trying to read a file in the directory ./resources/input_file.utf8. However, when I compile the following code from the terminal with the command:
python namefile.py input this error appears:
[Errno 2] No such file or directory: 'input' This is my code:
from argparse import ArgumentParser def parse_args(): parser = ArgumentParser() parser.add_argument("input_path", help="./resources/input_file.utf8") return parser.parse_args() def foo(input_path): file_input = open(input_path, "r", encoding='utf-8-sig') for line in file_input: [...] if __name__ == '__main__': args = parse_args() predict(args.input_path) One of the specification I have to respect is to not to put hard paths directly in the foo function, but only in the parser.add_argument() function.
How can I fix it?
python namefile.py resources/input_file.utf8?/. Relative paths starts from either the current directory or a well-known location (like~- your home directory)