简体   繁体   中英

how do you fix expected indented block error in python? I'm using PyCharm

I really don't know how do I fix this error? Since I already hit a tab after my line 4.

This is my code, very simple one:

import csv

def searchProxy():

card Identifier = input('Enter proxy\n')
csv_file = csv.reader(open ('\Users\Keanu\Documents\ARRMAIL07072021180029.CSV', 'r'))

for row Card Identifier in csv_file:
    if Card Identifier == row[0]:
            print(row)



print ('Enter to search card identifier')

src = int(input ("Enter here: "))

Error:

  File "C:\Users\Keanu\Documents\PythonProjects\main.py", line 5
    card Identifier = input('Enter proxy\n')
    ^
IndentationError: expected an indented block

Process finished with exit code 1

After def there should be some indentation. Also, don't use spaces when declaring the variables. Use a _ if you want to separate the name.

def searchProxy():

    card_Identifier = input('Enter proxy\n')
    csv_file = csv.reader(open ('\Users\Keanu\Documents\ARRMAIL07072021180029.CSV', 'r'))

    for row Card Identifier in csv_file:
        if Card Identifier == row[0]:
            print(row)

Unlike other programming languages which use {} to separate blocks of code, python uses indentation. So one should always keep that in mind when coding in python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM