Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Dump headers of parent nested tables

Aperta
#447 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Parti dal punto di ingresso tomlkit.dumps(my_dict) e confronta il suo output attuale con le intestazioni delle tabelle padre richieste. Determina come potrebbe essere esposta la formattazione desiderata, quindi verifica che le tabelle annidate apps.test.whatever_1 e apps.test.whatever_2 mantengano le proprie intestazioni e l'indentazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello,

  1. I was trying to convert this python dictionnary

    my_dict = {
        "apps": {
            "test": {
                "whatever_1": {
                    "date": "2025-12-16",
                },
                "whatever_2": {
                    "date": "2025-12-16",
                },
            },
        },
    }
    

    ...to this TOML output:

    [apps]
        [apps.test]
            [apps.test.whatever_1]
            date = "2025-12-16"
            [apps.test.whatever_2]
            date = "2025-12-16"
    
    
  2. I first had great hopes with:

    print(tomlkit.dumps(my_dict))
    

    but that outputs

    [apps.test.whatever_1]
    date = "2025-12-16"
    
    [apps.test.whatever_2]
    date = "2025-12-16"
    
  3. With a bit of pain, I eventually manage to get the expected output using:

    my_dict_new = tomlkit.document()
    for category_name, apps in my_dict.items():
        cat = tomlkit.table(False)
        for app_name, app_reports in apps.items():
            app = tomlkit.table(False).indent(4)
            for report_name, report_data in app_reports.items():
                rep = tomlkit.table(False).indent(4)
                for key, val in report_data.items():
                    rep.add(key, val).indent(4) 
                app.append(report_name, rep)
            cat.append(app_name, app)
        my_dict_new.append(category_name, cat)
    
    print(tomlkit.dumps(my_dict_new))
    

As this the reverse scenario from #47 and #107 in which the target output here seemed to be the default .dumps() output at the time, I wonder whether there would be a quicker way to access the old behavior again (i.e. dump headers for parent nested headers) ?

Lingua principale
Python
Stelle
850
Fork
163
Merge medio
13m
PR unite (30g)
2

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-poetry/tomlkit

Tutte le issue di python-poetry/tomlkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.