You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for your response.
It works fine when I add one property as below
import tomlkit
doc = tomlkit.document()
a = tomlkit.aot()
t = tomlkit.table()
t.add("name", "test")
t.add(tomlkit.key(["a", "prop1"]), "value1")
a.append(t)
doc.add("test", a)
print(tomlkit.dumps(doc))
But as soon as I add a second property, it fails.
import tomlkit
doc = tomlkit.document()
a = tomlkit.aot()
t = tomlkit.table()
t.add("name", "test")
t.add(tomlkit.key(["a", "prop1"]), "value1")
t.add(tomlkit.key(["a", "prop2"]), "value2")
a.append(t)
doc.add("test", a)
print(tomlkit.dumps(doc))
With the error
Traceback (most recent call last):
File "test-tomlkit.py", line 9, in <module>
t.add(tomlkit.key(["a", "prop2"]), "value2")
File "C:\Users\user1\Anaconda3\lib\site-packages\tomlkit\items.py", line 1385, in add
return self.append(key, value)
File "C:\Users\user1\Anaconda3\lib\site-packages\tomlkit\items.py", line 1491, in append
self._value.append(key, _item)
File "C:\Users\user1\Anaconda3\lib\site-packages\tomlkit\container.py", line 188, in append
self._handle_dotted_key(key, item)
File "C:\Users\user1\Anaconda3\lib\site-packages\tomlkit\container.py", line 150, in _handle_dotted_key
self.append(name, value)
File "C:\Users\user1\Anaconda3\lib\site-packages\tomlkit\container.py", line 243, in append
self._table_keys[-1] != current_body_element[0]
IndexError: list index out of range
Activity
frostming commentedon Jul 14, 2023
use
tomlkit.key([key1, key2])to get dotted key, or it will be regarded as a single key. The example would be:corrantho commentedon Jul 15, 2023
Thank you for your response.
It works fine when I add one property as below
But as soon as I add a second property, it fails.
With the error
corrantho commentedon Jul 15, 2023
I think it's fixed by #284
It appears I'm using an outdated version of tomlkit.