本文整理匯總了Python中argparse.FileType方法的典型用法代碼示例。如果您正苦於以下問題:Python argparse.FileType方法的具體用法?Python argparse.FileType怎麽用?Python argparse.FileType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類argparse
的用法示例。
在下文中一共展示了argparse.FileType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_arguments
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def add_arguments(self, parser):
parser.add_argument('input_file', type=argparse.FileType('r'), help='The file to process')
parser.add_argument('unit', type=str,
help='The short name of the unit all the notes will be added under, (e.g. "CMPT")')
parser.add_argument('--dry-run', '-n',
action='store_true',
dest='dry_run',
help='Don\'t actually save the data',
default=False,
)
parser.add_argument('--verbose',
action='store_true',
dest='verbose',
help='Print verbose output. Same as setting -v > 1',
default=False)
parser.add_argument('--markup', '-m',
dest='markup',
default='html',
help='Choices are: %s.' % get_markup_choices())
示例2: add_command_args
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def add_command_args(parser):
group = parser.add_mutually_exclusive_group()
group.add_argument("--watch", action="store_true", help="Monitor submitted job, stream log until job completes")
group.add_argument("--wait", action="store_true",
help="Block on job. Exit with code 0 if job succeeded, 1 if failed")
group = parser.add_mutually_exclusive_group()
group.add_argument("--command", nargs="+", help="Run these commands as the job (using " + BOLD("bash -c") + ")")
group.add_argument("--execute", type=argparse.FileType("rb"), metavar="EXECUTABLE",
help="Read this executable file and run it as the job")
group.add_argument("--wdl", type=argparse.FileType("rb"), metavar="WDL_WORKFLOW",
help="Read this WDL workflow file and run it as the job")
parser.add_argument("--wdl-input", type=argparse.FileType("r"), metavar="WDL_INPUT_JSON", default=sys.stdin,
help="With --wdl, use this JSON file as the WDL job input (default: stdin)")
parser.add_argument("--environment", nargs="+", metavar="NAME=VALUE",
type=lambda x: dict(zip(["name", "value"], x.split("=", 1))), default=[])
parser.add_argument("--staging-s3-bucket", help=argparse.SUPPRESS)
示例3: cmdline
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def cmdline():
import argparse
parser = argparse.ArgumentParser(description='Generate an svg wallpaper')
parser.add_argument('--width', type=int, default=1024,
help='The width of the wallpaper')
parser.add_argument('--height', type=int, default=786,
help='The height of the wallpaper')
parser.add_argument('--seed',
help='Seed for the randomizer')
parser.add_argument('--log-choices',
help='Log the choices made', action='store_true')
parser.add_argument('--output', type=argparse.FileType('w'),
default='-')
args = parser.parse_args()
for element in get_svg_iter(args.width, args.height,
{"seed": args.seed},
log_choices=args.log_choices):
args.output.write(element)
示例4: add_arguments
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def add_arguments(parser):
parser.add_argument(
'--output-json',
type=argparse.FileType('w'),
help='A json file to output information about the roll to.')
parser.add_argument(
'--verbose-json',
action='store_true',
help=(
'Emit even more data in the output-json file. Requires --output-json.'
))
def _launch(args):
from .cmd import main
return main(args)
def _postprocess_func(error, args):
if args.verbose_json and not args.output_json:
error('--verbose-json passed without --output-json')
parser.set_defaults(
func=_launch, postprocess_func=_postprocess_func)
示例5: add_common_monolingual_args
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def add_common_monolingual_args(task_parser):
task_parser.add_argument('infile',
type=argparse.FileType('r',encoding=DEFAULT_ENCODING),
nargs='?',
default=sys.stdin,
help='Input File path',
)
task_parser.add_argument('outfile',
type=argparse.FileType('w',encoding=DEFAULT_ENCODING),
nargs='?',
default=sys.stdout,
help='Output File path',
)
task_parser.add_argument('-l', '--lang',
help='Language',
)
示例6: add_common_bilingual_args
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def add_common_bilingual_args(task_parser):
task_parser.add_argument('infile',
type=argparse.FileType('r',encoding=DEFAULT_ENCODING),
nargs='?',
default=sys.stdin,
help='Input File path',
)
task_parser.add_argument('outfile',
type=argparse.FileType('w',encoding=DEFAULT_ENCODING),
nargs='?',
default=sys.stdout,
help='Output File path',
)
task_parser.add_argument('-s', '--srclang',
help='Source Language',
)
task_parser.add_argument('-t', '--tgtlang',
help='Target Language',
)
示例7: add_wc_parser
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def add_wc_parser(subparsers):
task_parser=subparsers.add_parser('wc', help='wc help')
task_parser.add_argument('infile',
type=argparse.FileType('r',encoding=DEFAULT_ENCODING),
nargs='?',
default=sys.stdin,
help='Input File path',
)
# task_parser.add_argument('-l', action='store_true')
# task_parser.add_argument('-w', action='store_true')
# task_parser.add_argument('-c', action='store_true')
# task_parser.set_defaults(l=False)
# task_parser.set_defaults(w=False)
# task_parser.set_defaults(c=False)
task_parser.set_defaults(func=run_wc)
示例8: create_parser
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def create_parser():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="learn BPE-based word segmentation")
parser.add_argument(
'--input', '-i', type=argparse.FileType('r'), default=sys.stdin,
metavar='PATH',
help="Input file (default: standard input).")
parser.add_argument(
'--codes', '-c', type=argparse.FileType('r'), metavar='PATH',
required=True,
help="File with BPE codes (created by learn_bpe.py).")
parser.add_argument(
'--output', '-o', type=argparse.FileType('w'), default=sys.stdout,
metavar='PATH',
help="Output file (default: standard output)")
parser.add_argument(
'--separator', '-s', type=str, default='@@', metavar='STR',
help="Separator between non-final subword units (default: '%(default)s'))")
return parser
示例9: cli
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def cli():
"""Command-line interface to the tool."""
streaming_clients = find_streaming_clients()
parser = ArgumentParser(description=__doc__)
parser.add_argument('--outfile', type=FileType('wb', encoding='utf-8'),
default=stdout,
help='File to which to write events')
parser.add_argument('--receiver', choices=sorted(streaming_clients),
required=True, default='kafka',
help='The receiver to use')
parser.add_argument('config', type=json_arg,
help='JSON configuration passed to the receiver')
args = parser.parse_args()
receive(args.outfile, streaming_clients[args.receiver], args.config)
示例10: cli
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def cli():
"""Command-line interface to the tool."""
streaming_clients = find_streaming_clients()
parser = ArgumentParser(description=__doc__)
parser.add_argument('--infile', type=FileType('r', encoding='utf-8'),
default=stdin,
help='File with events to send')
parser.add_argument('--sender', choices=sorted(streaming_clients),
required=True, default='kafka',
help='The sender to use')
parser.add_argument('config', type=json_arg,
help='JSON configuration passed to the sender')
args = parser.parse_args()
send(args.infile, streaming_clients[args.sender], args.config)
示例11: create_parser
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def create_parser():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="learn BPE-based word segmentation")
parser.add_argument(
'--input', '-i', type=argparse.FileType('r'), default=sys.stdin,
metavar='PATH',
help="Input text (default: standard input).")
parser.add_argument(
'--output', '-o', type=argparse.FileType('w'), default=sys.stdout,
metavar='PATH',
help="Output file for BPE codes (default: standard output)")
parser.add_argument(
'--symbols', '-s', type=int, default=10000,
help="Create this many new symbols (each representing a character n-gram) (default: %(default)s))")
parser.add_argument(
'--min-frequency', type=int, default=2, metavar='FREQ',
help='Stop if no symbol pair has frequency >= FREQ (default: %(default)s))')
parser.add_argument(
'--verbose', '-v', action="store_true",
help="verbose mode.")
return parser
示例12: parse_args
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def parse_args():
"""Handle the command line arguments.
Returns:
Output of argparse.ArgumentParser.parse_args.
"""
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--output', default='request.json',
help='Output file to write encoded images to.')
parser.add_argument('-r', '--resize', dest='resize', action='store_true',
help='Will resize images locally first. Not needed, but'
' will reduce network traffic.')
parser.add_argument('inputs', nargs='+', type=argparse.FileType('r'),
help='A list of .jpg or .jpeg files to serialize into a '
'request json')
args = parser.parse_args()
check = lambda filename: filename.lower().endswith(('jpeg', 'jpg'))
if not all(check(input_file.name) for input_file in args.inputs):
sys.stderr.write('All inputs must be .jpeg or .jpg')
sys.exit(1)
return args
示例13: main
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--max-no-articles", type = int, default=10,
help = "maximum number of articles to download")
parser.add_argument("-w", "--no-words", type = int, default=1000000,
help = "target number of words")
parser.add_argument("-s", "--search",
help = "if specified will use this search term")
parser.add_argument("language",
help = "2 letter language code")
parser.add_argument("output", type = argparse.FileType('w'),
help = "output file")
args = parser.parse_args()
articles = get_articles(**vars(args))
corpusxml = articles2xml(articles)
xmlstr = lxml.etree.tostring(corpusxml,
pretty_print=True,
xml_declaration=True,
encoding='utf-8')
args.output.write(xmlstr.decode('utf-8'))
示例14: main
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def main():
parser = argparse.ArgumentParser(description='King Phisher Signing-Key Generation Utility', conflict_handler='resolve')
utilities.argp_add_args(parser)
subparsers = parser.add_subparsers(dest='subcommand')
subparsers.required = True
parser_display = subparsers.add_parser('display')
parser_display.set_defaults(action=action_display)
parser_display.add_argument('file', default=os.getenv('KING_PHISHER_DEV_KEY'), nargs='?', help='the key file to display')
parser_generate = subparsers.add_parser('generate')
parser_generate.set_defaults(action=action_generate)
parser_generate.add_argument('id', help='this key\'s identifier')
parser_generate.add_argument('file', type=argparse.FileType('w'), help='the destination to write the key to')
arguments = parser.parse_args()
find.init_data_path()
arguments.action(arguments)
示例15: parse_args
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import FileType [as 別名]
def parse_args(args: Sequence) -> argparse.Namespace:
"""Parse command-line arguments."""
parser = argparse.ArgumentParser(
description=(
"A blazing fast LookML parser, implemented in pure Python. "
"When invoked from the command line, "
"returns the parsed output as a JSON string."
)
)
parser.add_argument(
"file", type=argparse.FileType("r"), help="path to the LookML file to parse"
)
parser.add_argument(
"-d",
"--debug",
action="store_const",
dest="log_level",
const=logging.DEBUG,
default=logging.WARN,
help="increase logging verbosity",
)
return parser.parse_args(args)