Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Dict Problem :(
-
Hello guys,
P.S.:
I know it has nothing to do with Pythonista, but I need your helpI‘ve got an Dict problem and the german Python-Forum couden‘t help me in this case i Hope anyone of you can do it.....
But my english is really not the best for That to explain it correct sorry for that
I Use this Dict (when it is Bad and there is a Better way Tell me please) to Save my content.
My plan is Now to sort That Dict for the Key structure but i have no idea How and whether it works at all....
This is wrong (this is my file):
customer_folder = { 'Kunden Übersicht': { 'structure': { 2: {}, '01_Beschreibung': { 'Beschriftung Verteilungen.smg': {}, 'Beschriftung Verteilungen.xlsx': {}, }, }, 'structure': { 1: {}, '02_Materiallisten': { 'Projekt-name': { 'Eintragungen': {}, 'Geschlossen': {}, 'Zwischenrechnung': {}, }, }, }, 'structure': { 3: {}, '03_Prüfungen': {}, }, '04_KNX': { 'structure': { 4 }, }, '05_Bilder': { 'structure': { 5 }, }, '06_Notizen': { 'structure': { 6 }, }, '07_Datenbank': { 'structure': { 7 }, }, } }
This is how i want it (this is needed when i read the file):
customer_folder = { 'Kunden Übersicht': { 'structure': { 1: {}, '02_Materiallisten': { 'Projekt-name': { 'Eintragungen': {}, 'Geschlossen': {}, 'Zwischenrechnung': {}, }, }, }, 'structure': { 2: {}, '01_Beschreibung': { 'Beschriftung Verteilungen.smg': {}, 'Beschriftung Verteilungen.xlsx': {}, }, }, 'structure': { 3: {}, '03_Prüfungen': {}, }, '04_KNX': { 'structure': { 4 }, }, '05_Bilder': { 'structure': { 5 }, }, '06_Notizen': { 'structure': { 6 }, }, '07_Datenbank': { 'structure': { 7 }, }, } }
I would be very happy if one of you could help me.
-
It is strange that sometimes you have the numbers as keys of dicts, sometimes they are dict values. Maybe that's what you want, but it seems confusing.
-
You are repeating the key
structure
multiple times so only the last one will be used.Perhaps…
customer_folder = { 'Kunden Übersicht': { '01_Beschreibung': { 'Beschriftung Verteilungen.smg': {}, 'Beschriftung Verteilungen.xlsx': {}, 'structure': {1}, }, '02_Materiallisten': { 'Projekt-name': { 'Eintragungen': {}, 'Geschlossen': {}, 'Zwischenrechnung': {}, }, 'structure': {2}, }, '03_Prüfungen': { 'structure': {3}, }, '04_KNX': { 'structure': {4}, }, '05_Bilder': { 'structure': {5}, }, '06_Notizen': { 'structure': {6}, }, '07_Datenbank': { 'structure': {7}, }, }, }
-
@DavinE I wonder if you intended to have a key called structure, which contains a
list
of values. That way you can access['structure'][4]
-
If there is a discussion of what you want on the German Python-Forum then please post a URL here for those who speak German.
customer_folder = { 'Kunden Übersicht': [ { '01_Beschreibung': { 'Beschriftung Verteilungen.smg': {}, 'Beschriftung Verteilungen.xlsx': {}, }, }, { '02_Materiallisten': { 'Projekt-name': { 'Eintragungen': {}, 'Geschlossen': {}, 'Zwischenrechnung': {}, }, }, }, { '03_Prüfungen': {}, }, { '04_KNX': {}, }, { '05_Bilder': {}, }, { '06_Notizen': {}, }, { '07_Datenbank': {}, }, ], } # Indexing will be off by one from the title. print(customer_folder['Kunden Übersicht'][0]) # '01_Beschreibung': {... print(customer_folder['Kunden Übersicht'][6]) # '07_Datenbank': {...
-
Think my Plan doesn't work with dicts.... i try it with an MySQL Table
here is the Link:
https://www.python-forum.de/viewtopic.php?f=1&t=52737this is closed, thanks for your replies