当前位置: 首页>>代码示例>>Python>>正文


Python argparse.FileType方法代码示例

本文整理汇总了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()) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:notes_import.py

示例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) 
开发者ID:kislyuk,项目名称:aegea,代码行数:18,代码来源:batch.py

示例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) 
开发者ID:ondergetekende,项目名称:python-panavatar,代码行数:24,代码来源:__init__.py

示例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) 
开发者ID:luci,项目名称:recipes-py,代码行数:23,代码来源:__init__.py

示例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',
            ) 
开发者ID:anoopkunchukuttan,项目名称:indic_nlp_library,代码行数:18,代码来源:cliparser.py

示例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',
            ) 
开发者ID:anoopkunchukuttan,项目名称:indic_nlp_library,代码行数:22,代码来源:cliparser.py

示例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) 
开发者ID:anoopkunchukuttan,项目名称:indic_nlp_library,代码行数:19,代码来源:cliparser.py

示例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 
开发者ID:nusnlp,项目名称:crosentgec,代码行数:24,代码来源:apply_bpe.py

示例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) 
开发者ID:microsoft,项目名称:agogosml,代码行数:18,代码来源:receiver.py

示例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) 
开发者ID:microsoft,项目名称:agogosml,代码行数:18,代码来源:sender.py

示例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 
开发者ID:fabiencro,项目名称:knmt,代码行数:26,代码来源:learn_bpe.py

示例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 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-samples,代码行数:27,代码来源:images_to_json.py

示例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')) 
开发者ID:Idlak,项目名称:Living-Audio-Dataset,代码行数:27,代码来源:gen_corpus.py

示例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) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:20,代码来源:key_tool.py

示例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) 
开发者ID:joshtemple,项目名称:lkml,代码行数:25,代码来源:__init__.py


注:本文中的argparse.FileType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。