2

I used the following code:

for item in users_dict['items']:
    sl_no = sl_no + 1
    user_id_pass = item['user_id']
    account_id_pass = item['account_id']
    Name_pass = item['display_name']

    if 'age' in item:
        age_pass = item['age']
    else:
        age_pass = 0

    stack_link_pass = item['link']
    user_type_pass = item['user_type']
    Location_pass = item['location']

    if 'website_url' in item:
        website_link_pass = item['website_url']
    else:
        website_link_pass = 'NA'

I am getting this error:

 user_id_pass = item['user_id']
    ^
IndentationError: unexpected indent

please help me out

4
  • 3
    Mixed tabs and spaces? Commented Jun 28, 2017 at 19:18
  • Check for spaces and tabs. Use only either of one uniformly. Commented Jun 28, 2017 at 19:19
  • There's a tab in front at the start of this line. Don't mix tabs and spaces. It is recommended to use four spaces for each indent level. Commented Jun 28, 2017 at 19:22
  • Thanks all. I got it. Commented Jun 30, 2017 at 11:18

3 Answers 3

2

As I see that all your lines are indented with the correct amount of spaces, please check that your using either tabs or spaces to indent.

For example you may have run into this situation:

    {4 spaces}sl_no = sl_no + 1
    {--1 tab-}user_id_pass = item['user_id']
    {4 spaces}account_id_pass = item['account_id']
Sign up to request clarification or add additional context in comments.

1 Comment

Great to know! :) Would you mind marking this as the answer if it's the case?
0

In Python, you can only use one or the other, tabs or spaces, to indent your code. Since tabs and spaces are encoded differently, the interpreter can't tell where your if statement ends. Backspace over all of your indentations, then just tab or space every line the number of indents you prefer.

Comments

0

To Enhance it more for someone who gets into this situation. In your most widely used code editors. VSCode or Sublime Text.

Type a sequence "Ctrl+Shift+P" a command box will open

In that type "Indentation: Convert to Spaces" or similarly "Indentation: Convert to Tabs". It will manage all the tabs and spaces and convert them to a uniform type. Correct the formatting and you are good to go.

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.