-3

i have aproblem with indent this code

if response.status_code == 200:
    #print(response.text)
    string=response.text
    #print(response.text)
    results = re.findall(r'<th scope="row">(.*?)</th>\n.*?<td>(.*?)</td>\n.*?<td>(.*?)</td>\n.*?<td>(.*?)</td>', string, re.DOTALL)
    for t in results:
    print(t)
else:
    print("Errore nella richiesta, codice di stato:", response.status_code)

i think is correct but return me error File "/home/stefano/Desktop/test.py", line 68 print(t) TabError: inconsistent use of tabs and spaces in indentation

i try to reduce tab and use space but return error again


if response.status_code == 200:
    #print(response.text)
    string=response.text
    #print(response.text)
    results = re.findall(r'<th scope="row">(.*?)</th>\n.*?<td>(.*?)</td>\n.*?<td>(.*?)</td>\n.*?<td>(.*?)</td>', string, re.DOTALL)
    for t in results:
    print(t)
else:
    print("Errore nella richiesta, codice di stato:", response.status_code)

i hope one day everyone create a fork of python without indentation Hell

  • 3
    how is your editor configured? the standard is to use spaces instead of tabs, so if your editor introduces 4 spaces every time you press tab button you should not have any problem. Any modern code editor has this option – Sembei Norimaki Jan 31 '23 at 09:40
  • Does this answer your question? ["inconsistent use of tabs and spaces in indentation"](https://stackoverflow.com/questions/5685406/inconsistent-use-of-tabs-and-spaces-in-indentation) – Gino Mempin Jan 31 '23 at 09:54

1 Answers1

1

Inside the if statement there is a for loop which has no indentation. The correct code should be:

if response.status_code == 200:
    #print(response.text)
    string=response.text
    #print(response.text)
    results = re.findall(r'<th scope="row">(.*?)</th>\n.*?<td>(.*?)</td>\n.*?<td>(.*?)</td>\n.*?<td>(.*?)</td>', string, re.DOTALL)
    for t in results:
        print(t)
else:
    print("Errore nella richiesta, codice di stato:", response.status_code)
Marcello Zago
  • 629
  • 5
  • 19
  • yea work @Marcello Zago thanks so much – ernesto gevara Jan 31 '23 at 17:56
  • @Sembei Norimaki i use Geany and in preferences --> editor --->indentation i have width 4 type: tabs and spaces , auto indentmode current chars tabkey indents flagged – ernesto gevara Jan 31 '23 at 18:00
  • @ernestogevara If it works, think about accepting the answer. And another tip I can give you is to always check whether your IDE/ text editor shows you an error. Or to read your errors carefully to find the line where your error occurs. – Marcello Zago Feb 01 '23 at 07:54