0

I have a dictionary with many entries of the following form:

dictionary = {"label":{entryBox:1},...}

Where the entryBox corresponds to an object elsewhere in my code.

I want to make a function that returns the value (1) given just the entryBox passed as an argument.

Ex.

def fxn(entryObject):
    return dictionary["entryObject"][entryObject]

My question lies in the ["entryOnject"] as this does not represent the argument passed but rather "entryObject" in quotes.

How do I make whats between the quotes a variable and have it still surrounded by double quotes.

I have tried converting it to a string with str() and using an fstring but neither worked for my application.

Thank you in advance.

apady111
  • 3
  • 2
  • 5
    According to the first example, it would be `dictionary["label"][entryObject]` – John Gordon Jul 08 '21 at 03:47
  • If you mean something like `'"entryObject"'` then you can escape double quotes like so `"\"entryObject\""`. – David Lee Jul 08 '21 at 03:47
  • 1
    If i got the question right, thats what you need: https://stackoverflow.com/questions/18425225/getting-the-name-of-a-variable-as-a-string – Gabriel Hilgert Jul 08 '21 at 03:47
  • "How do I make whats between the quotes a variable and have it still surrounded by double quotes." This doesn't make much sense. Can you give a simple, concrete (and complete) example of the sort of thing you are trying to accomplish? – juanpa.arrivillaga Jul 08 '21 at 04:04
  • The quotes are not part of the name. The key in your very first example is `label`. The name does not contain quotes. You have to WRITE it with quotes to tell Python it's a constant string, and Python will print it with quotes for the same reason, but if you pass in a variable containing the string `label`, then you just cite the variable name. – Tim Roberts Jul 08 '21 at 04:36
  • `dictionary["entryObject"]` is a static key reference that will only ever access entryObject. – Derek Jul 08 '21 at 06:26

0 Answers0