0

I am using an api which searches for tvshows and returns an id, the issue I have is that if I save the search as a variable and print the variable it returns output like this:

for result in show:
a = (result.id)
print(a)

84661
30191
30287
80987
111713
8108
50813
72444
42117
22306
4807

I want to save the first result as a variable that I can use later. Have tried a few different things like os.system("echo " + a + " | head -1") but this returns 4807 not 84661, same for awk and sed. What am I doing wrong? I've tried saving the variable as list, str and array but am unable to grab just the first line, It keeps getting the last one.

1 Answer 1

1
firstIdvariable = show[0].id  

try that code

Sign up to request clarification or add additional context in comments.

1 Comment

thanks that was it, im new to python and was trying show.id[0], will accept answer as soon as it lets me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.