Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide simple access to defined keys of a parser instance #45

Closed
carloshorn opened this issue Nov 11, 2022 · 1 comment · Fixed by #46
Closed

Provide simple access to defined keys of a parser instance #45

carloshorn opened this issue Nov 11, 2022 · 1 comment · Fixed by #46

Comments

@carloshorn
Copy link
Contributor

Feature Request

Description

The parser.Parser class should provide a public method to access the defined keys of the underlying file format.

User Story

As a developer, I want to programmatically extract the defined identifiers of a given filename format, so I can know in advance which metadata is available before getting an actual filename or manually inspect the format.

Current Workaround(s)

  1. Parse a valid filename and look at the result keys.
  2. Use a string formatter: {field_name for literal_text, field_name, format_spec, conversion in string.Formatter().parse(fmt)}
@djhoese
Copy link
Member

djhoese commented Nov 12, 2022

Very good idea!

Your workaround and looking at the existing code makes me wonder if we should maybe update the Parser class to do some of the format string specific stuff on __init__ and use it in all sub-methods/functions as an optimization. Like the conversion dictionary. I'm not sure that would be something users would need access to, but could be a nice little optimization.

At this point I guess I'll say "pull requests welcome" 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants