1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Manual dictionary entry missing when imported into another file

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024 às 00:22.

  1. Stack

    Stack Membro Participativo

    I have a file where a dictionary is created from reading contents of an excel file. There is a manual entry to the dictionary that's missing when accessed from the second file... (simplified code)

    In ref.py, the manual entry being "x":"xyz".

    # ref.py
    import pandas as pd

    df = pd.read_excel('dictfile.xlsx', sheet_name="ref")

    def make_dict():
    temp_dict = {"x":"xyz"}
    for i,r in df.iterrows():
    temp_dict[r['key']] = r['value']
    return temp_dict

    final_dict = make_dict()


    Printing the dictionary:

    {'x': 'xyz', 'a': 'aaa', 'b': 'bbb', 'c': 'ccc'}


    In another file, I'm importing this file so I can reference the dictionary. The dictionary is accessible EXCEPT for the xyz entry.

    # run_template.py
    from scrap import final_dict

    final_dict


    Printing the dictionary:

    {'a': 'aaa', 'b': 'bbb', 'c': 'ccc'}

    Continue reading...

Compartilhe esta Página