Answer the question
In order to leave comments, you need to log in
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
{
"test1": [
{
"recieve": "148804ko",
"pulselenght": "228",
"protocol": "3"
}
]
}
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
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question