tomlkit icon indicating copy to clipboard operation
tomlkit copied to clipboard

Comments in multiline array

Open andreasdoll opened this issue 4 months ago • 0 comments

Hello

I have two questions regarding comments in multiline arrays (for which I couldn't find documentation).

I'm using tomlkit 0.12.4. Consider the following code:

import tomlkit

content = """[foo]
bar = [
    "one", # comment one
    "two", # comment two
]
"""

data = tomlkit.loads(content)
  • Is there a way to read the comments with respect to the array entries?

I was expecting data["foo"]["bar"][0].trivia, but this doesn't have information about the comment (neither does data["foo"]["bar"].trivia). I know I can do data["foo"]["bar"].as_string() but there I'd have to parse them myself from the string.

  • (How) can I write multiline arrays with comments?

Thanks in advance!

andreasdoll avatar Apr 19 '24 14:04 andreasdoll