omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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 :(

    Pythonista
    3
    6
    1361
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DavinE
      DavinE last edited by DavinE

      Hello guys,

      P.S.:
      I know it has nothing to do with Pythonista, but I need your help

      I‘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.

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by ccc

          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},
                  },
              },
          }
          
          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            @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]

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              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': {...
              
              1 Reply Last reply Reply Quote 0
              • DavinE
                DavinE last edited by

                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=52737

                this is closed, thanks for your replies

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors