Ciao,

mi sembra un caso da DSL, perciò potresti andare con
https://github.com/lark-parser/lark o strumenti simili (o fare riferimento
all'altro post sui parser)

Jacopo

Il giorno mer 10 lug 2019 alle ore 15:21 ㎝ <c...@python.it> ha scritto:

> Il giorno mer 10 lug 2019 alle ore 15:00 Gabriele Battaglia
> <iz4...@libero.it> ha scritto:
>
> > E' come se avessi:
> >
> > <Cliente>
> > nome: xxx, cognome: yyy, data: zzz
> > </Cliente>
> >
> > Ma anche:
> >
> > <Cliente>
> > data: zzz, cognome: yyy, nome: xxx
> > </Cliente>
> >
> > Perciò, quando assegno i dati alla tupla avrò che ogni record presenterà
> > campi diversi nella stessa posizione indicizzata: ad esempio db[0][0] ci
> > sarà il nome, mentre db[1][0] presenterà la data.
>
> Io ti consiglierei una lista di dict, o forse ancora meglio una lista
> di namedtuple
> ```
> >>> d1 = {'nome': 'xxx', 'cognome': 'yyy', 'data': 'zzz'}
> >>> d2 = {'data': 'zzz', 'cognome': 'yyy', 'nome': 'xxx'}
> >>> d1 == d2
> True
> >>> from collections import namedtuple
> >>> N = namedtuple('N', 'nome cognome data')
> >>> n1 = N(nome='xxx', cognome='yyy', data='zzz')
> >>> n2 = N(data='zzz', cognome='yyy', nome='xxx')
> >>> n1 == n2
> True
> >>> n1[0]
> 'xxx'
> >>> n2[0]
> 'xxx'
> ```
> ㎝
>
> --
> !!!! THE 🍺-WARE LICENSE (Revision ㊷):
>     <㎝@🐍.it> wrote this 📧. As long as you retain this notice you can
>     do whatever you want with this stuff. If we meet some day, and you
>     think this stuff is worth it, you can buy me a 🍺 in return. — ㎝
> _______________________________________________
> Python mailing list
> Python@lists.python.it
> https://lists.python.it/mailman/listinfo/python
>
_______________________________________________
Python mailing list
Python@lists.python.it
https://lists.python.it/mailman/listinfo/python

Rispondere a