Take a look at the documentation: https://docs.python.org/3/library/argparse.html#type
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('file', type=argparse.FileType('r'))
args = parser.parse_args()
print(args.file.readlines())
More Related Contents:
- Parsing boolean values with argparse
- How can I pass a list as a command-line argument with argparse?
- Simple argparse example wanted: 1 argument, 3 results
- Python argparse mutual exclusive group
- Can’t get argparse to read quoted string with dashes in it?
- Argparse optional positional arguments?
- How to insert newlines on argparse help text?
- Python argparse – Add argument to multiple subparsers
- Argparse: Required argument ‘y’ if ‘x’ is present
- How do you write tests for the argparse portion of a python module?
- Python argparse ignore unrecognised arguments
- Python argparse: default value or specified value
- Python Argparse conditionally required arguments
- Argparse with required subparser
- How to parse multiple nested sub-commands using python argparse?
- argparse subparser monolithic help output
- Display help message with Python argparse when script is called without any arguments
- Specify date format for Python argparse input arguments
- Why use argparse rather than optparse?
- Argparse – do not catch positional arguments with `nargs`.
- Conditional command line arguments in Python using argparse
- Python argparse command line flags without arguments
- Customize argparse help message
- type=dict in argparse.add_argument()
- Python argparse: Is there a way to specify a range in nargs?
- argparse argument order
- argparse subcommands with nested namespaces
- How can I constrain a value parsed with argparse (for example, restrict an integer to positive values)?
- Call function based on argparse
- Using the same option multiple times in Python’s argparse