A
A
Artem Marsh2018-11-11 17:10:51
Python
Artem Marsh, 2018-11-11 17:10:51

Error in code TypeError: 'int' object is not subscriptable, what should I do?

In general, I wrote the code on the VK API, but it does not work.
The code response was:

{'count': 18, 'items': [{'id': XXXXXXXX, 'first_name': 'LOL', 'last_name': 'LOLES', 'online': 0}

I tried to display only the First name, last name, online, but it didn’t work out, an error pops up:
TypeError: 'int' object is not subscriptable
The code itself is as follows:
def group_members():
    group = vk.groups.getMembers(group_id=164445012, fields=['first_name last_name, online'])
    name = ['items'][0]['first_name']
    print(name)
group_members()

What is my mistake?
Help me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-11-11
@true1337hax

You are accessing by keys, but you don’t specify which dictionary keys :) This would be more correct:
name = group['items'][0]['first_name']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question