1

Set-up

I scrape housing ads per city, using Scrapy. Per city I create a spider, which I adjust (a little) per city when needed.


Problem

I copy-pasted my code from City A in a .py file, intended to scrape City B. I've done this many times before. Now however I receive an IndentationError for the following lines in the code,

pl=[]
for key, value in df['postal'].iteritems():
    temp = value
    pl.append(str(temp))

The error is for temp and states IndentationError: expected an indented block. There is no indentation error if I run the code for city A. However, the copy-pasted code for B gives this error.

Moreover, if I enter or remove an extra white space, the lines run fine but then I receive an IndentationError at the next loop – enter/remove an extra white space at that loop will allow me to continue to the subsequent loop whereupon I receive the same error, etc.

I've also run python -m tabnanny yourfile.py as stated here, but to no effect: Clean bill of health.

What is going on here?

Community
  • 1
  • 1
LucSpan
  • 1,831
  • 6
  • 31
  • 66

2 Answers2

0

Left align all the copy pasted code and again give the proper indentation with tabs. copy pasted code sometimes takes wrong indentation.

Manpreet Ahluwalia
  • 301
  • 1
  • 3
  • 11
0

Ok. This was a silly thing.

I copy pasted the entire file, but not correctly. That is, at the top of the file where I state which modules to input there was an unnecessary indent. I.e.

     import pandas as pd

instead of,

import pandas as pd

This resulted in the indentation error at any loop.


LucSpan
  • 1,831
  • 6
  • 31
  • 66