Integrate the dictionary and complete the Python variables

0

I have this dic and I would like to work with him:

Inventory_data = {"Inventario_datos": {"Alti MW $ 2 |": {"Floor_price": '2.5', "Li_platform": "1"
                                                    "Excel_name": "Alti MW $ 2.xlsx", "Li_Publisher": "2",
                                                    "Tag_Rate": "2", "TagName": "Alti MW $ 2 |"}},
                                      {"Alti MW $ 3 |": {"Floor_price": '2.75', "Li_platform": "1",
                                                    "Excel_name": "Alti MW $ 2.25.xlsx", "Li_Publisher": "2",
                                                    "Tag_Rate": "2.25", "TagName": "Alti MW $ 2.25 |"}}, ...}

I build a program a few days ago and it works with Selenium (webdriver). This is part of the program code. Inventory_data has a field with the name of each group of values, in this case they are "Alti MW $ 2 |" and "Alti MW $ 3 |". What I'm looking for is that by typing the field somewhere in the code (for example, "Alti MW $ 2 |") write all the values within the field.

It would be something like this:

Escriba el campo = "Alti MW $ 2 |"

#Packs para completar
TagName = "{}"
Floor_price = '{}'
Li_platform = '// * [@ id = "platform_listbox"] / li [{}]'
Excel_name = '{}'
Li_Publisher = '// * [@ id = "publisher_listbox"] / li [{}]'
Tag_Rate = '{}'
terminado:

Escriba el campo = "Alti MW $ 2 |"
#Packs para completar
TagName = "Alti MW $ 2 |"
Floor_price = '2.8'
Li_platform = '// * [@ id = "platform_listbox"] / li [1]'
Excel_name = 'Alti MW $ 2.25.xlsx'
Li_Publisher = '// * [@ id = "publisher_listbox"] / li [2]'
    
asked by Martin Bouhier 06.10.2017 в 07:00
source

1 answer

0

I had to fix the declaration of your dictionary since it had syntax errors.

Inventory_data = {"Inventario_datos": {"Alti MW $ 2 |": {"Floor_price": '2.5', "Li_platform": "1",
                                                "Excel_name": "Alti MW $ 2.xlsx", "Li_Publisher": "2",
                                                "Tag_Rate": "2", "TagName": "Alti MW $ 2 |"},
                                  "Alti MW $ 3 |": {"Floor_price": '2.75', "Li_platform": "1",
                                                "Excel_name": "Alti MW $ 2.25.xlsx", "Li_Publisher": "2",
                                                "Tag_Rate": "2.25", "TagName": "Alti MW $ 2.25 |"}}}


key1 = "Inventario_datos"
key2 = "Alti MW $ 2 |"

print "Escriba el campo = %s" % key2
print "TagName %s" % Inventory_data[key1][key2]["TagName"]
print "Floor_price %s" % Inventory_data[key1][key2]["Floor_price"]
print "Li_platform %s" % Inventory_data[key1][key2]["Li_platform"]
print "Excel_name %s" % Inventory_data[key1][key2]["Excel_name"]
print "Li_Publisher %s" % Inventory_data[key1][key2]["Li_Publisher"]

Update If what you need is to record data in the dictionary, use the following code:

nuevo = dict()
nuevo["TagName"] = "Nuevo TagName"
nuevo["Floor_price"] = "Nuevo Floor_price"
nuevo["Li_platform"] = "Nuevo Li_platform"
nuevo["Excel_name"] = "Nuevo Excel_name"
nuevo["Li_Publisher"] = "Nuevo Li_Publisher"

Inventory_data["Inventario_datos"]["NuevoCampo"] = nuevo
print Inventory_data

You'll get:

{'Inventario_datos': {'Alti MW $ 3 |': {
    'Excel_name': 'Alti MW $ 2.25.xlsx',
    'Li_platform': '1',
    'Floor_price': '2.75',
    'Li_Publisher': '2',
    'Tag_Rate': '2.25',
    'TagName': 'Alti MW $ 2.25 |',
    }, 'Alti MW $ 2 |': {
    'Excel_name': 'Alti MW $ 2.xlsx',
    'Li_platform': '1',
    'Floor_price': '2.5',
    'Li_Publisher': '2',
    'Tag_Rate': '2',
    'TagName': 'Alti MW $ 2 |',
    }, 'NuevoCampo': {
    'Li_platform': 'Nuevo Li_platform',
    'Excel_name': 'Nuevo Excel_name',
    'Li_Publisher': 'Nuevo Li_Publisher',
    'TagName': 'Nuevo TagName',
    'Floor_price': 'Nuevo Floor_price',
    }}}
    
answered by 06.10.2017 в 16:54