[Python] python accessing single value from dictionary in another module

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have a separate module (file) with a dictionary of internal commands for my program.
    Trying to get one value of this dictionary always throws an exception using the 'get' command.
    How do I access the values correctly? (Python 3.13.2 )

    commands.py

    cmd_list = {
    "one": b'A',
    "two": b'B',
    "three": b'C'
    }


    main.py

    import commands

    cmd = "one"
    cmd_value = commands.cmd_list.get(cmd)
    # ^^^^^^^^
    # Exception has occurred: AttributeError
    # partially initialized module 'commands' from '...\commands.py' has no attribute 'cmd_list' (most likely due to a circular import)

    Continue reading...

Compartilhe esta Página