我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用optparse.TitledHelpFormatter()。
def __init__(self, components=(), defaults=None, read_config_files=None, *args, **kwargs): """ `components` is a list of Docutils components each containing a ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. """ self.lists = {} """Set of list-type settings.""" self.config_files = [] """List of paths of applied configuration files.""" optparse.OptionParser.__init__( self, option_class=Option, add_help_option=None, formatter=optparse.TitledHelpFormatter(width=78), *args, **kwargs) if not self.version: self.version = self.version_template # Make an instance copy (it will be modified): self.relative_path_settings = list(self.relative_path_settings) self.components = (self,) + tuple(components) self.populate_from_components(self.components) self.set_defaults_from_dict(defaults or {}) if read_config_files and not self.defaults['_disable_config']: try: config_settings = self.get_standard_config_settings() except ValueError, error: self.error(error) self.set_defaults_from_dict(config_settings.__dict__)
def __init__(self, components=(), defaults=None, read_config_files=None, *args, **kwargs): """ `components` is a list of Docutils components each containing a ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. """ self.lists = {} """Set of list-type settings.""" self.config_files = [] """List of paths of applied configuration files.""" optparse.OptionParser.__init__( self, option_class=Option, add_help_option=None, formatter=optparse.TitledHelpFormatter(width=78), *args, **kwargs) if not self.version: self.version = self.version_template # Make an instance copy (it will be modified): self.relative_path_settings = list(self.relative_path_settings) self.components = (self,) + tuple(components) self.populate_from_components(self.components) self.set_defaults_from_dict(defaults or {}) if read_config_files and not self.defaults['_disable_config']: try: config_settings = self.get_standard_config_settings() except ValueError, error: self.error(SafeString(error)) self.set_defaults_from_dict(config_settings.__dict__)
def __init__(self, components=(), defaults=None, read_config_files=None, *args, **kwargs): """ `components` is a list of Docutils components each containing a ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. """ self.lists = {} """Set of list-type settings.""" self.config_files = [] """List of paths of applied configuration files.""" optparse.OptionParser.__init__( self, option_class=Option, add_help_option=None, formatter=optparse.TitledHelpFormatter(width=78), *args, **kwargs) if not self.version: self.version = self.version_template # Make an instance copy (it will be modified): self.relative_path_settings = list(self.relative_path_settings) self.components = (self,) + tuple(components) self.populate_from_components(self.components) self.set_defaults_from_dict(defaults or {}) if read_config_files and not self.defaults['_disable_config']: try: config_settings = self.get_standard_config_settings() except ValueError as error: self.error(SafeString(error)) self.set_defaults_from_dict(config_settings.__dict__)
def __init__(_): ihf = optparse.IndentedHelpFormatter(2, 60, 120) optparse.OptionParser.__init__(_, prog = APPNAME, usage = "python tp.py <tags or options>", version = APPNAME + " (C) Arne Bachmann Release version " + __version__, formatter = ihf) # , formatter = optparse.TitledHelpFormatter(),
def process_command_line_old(argv): """ Process command line arguments """ help_text = 'Usage: python pycollimate.py 1 ti2_track_out_1.tfsone initial_distribution\n' if argv is None: argv = sys.argv[1:] # initialize the parser object: parser = optparse.OptionParser( formatter=optparse.TitledHelpFormatter(width=78), add_help_option=None) # define options here: parser.add_option( # customized description; put --help last '-h', '--help', action='help', help=help_text) parser.set_defaults(coll_index=1, file_input='twiss_input.tfs', file_out='initial_distribution', black=False) parser.add_option('-o', '--output', dest='file_out') parser.add_option('-i', '--input', dest='file_input') parser.add_option('-b', '--black', action='store_true', dest='black', help='Black absorber switch') parser.add_option('-n', '--number', type="int", dest="coll_index", help='Collimator index and seed') options, args = parser.parse_args(argv) return options, args