V
V
Valery Zhmyshenko2020-12-17 11:49:05
Python
Valery Zhmyshenko, 2020-12-17 11:49:05

How to get a separate value from def'a?

Hello! There is this function:

def get_info_by_name(name):
  with open("data.json", "r") as read_file:
    data = json.load(read_file)
    recieve = data[name][0]["recieve"]
    pulselenght = data[name][0]["pulselenght"]
    protocol = data[name][0]["protocol"]
    return recieve, pulselenght, protocol

json file:
{
  "test1": [ 
  {
    "recieve": "148804ko",
    "pulselenght": "228",
    "protocol": "3"
  }
 ]
}

And then I print:
print("Hello! 1>Listen 2>Send 3>Read data from json")
choose = int(input("> "))

if choose == 1:
  pass
if choose == 2:
  print("Enter name of record")
  name = input("> ")
  print(get_info_by_name(name))

if choose == 3:
  pass

And here is the output:
5fdb1b5b67b21556688419.png
How can I get these values ​​​​separately? (These are ('148804ko', '228', '3') )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-12-17
@mcborrrov

Read at least the beginning of any textbook, and then apply the knowledge gained in order to use the operation of taking an element by index:print(get_info_by_name(name)[0])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question