0

I am a newbie in Python.

I have written some code but when I compile, it fails It shows error 'unindent does not match any outer indentation level'

I'm coding in Sublime Text 2. How can I fix it? Thank you very much.

image_source = PythonMagick.Image(image_source_path)
image_dest = PythonMagick.Image(image_dest_path)
image_combine = composite_images(imageSource, imageDest, dest_x, dest_y)

if os.path.isfile(image_1_path) == True:
   image_1 = PythonMagick.Image(image_1_path)
   image_combine = composite_images(image_combine, image_1, image_1_x, image_1_y)

image_2 = PythonMagick.Image(image_2_path) ===> **ERROR HERE**
img = composite_images(image_combine, image_2, image_2_x, image_2_y)
tmp_path = combine_folder_full_path
img.write(tmp_path)
lolyoshi
  • 1,536
  • 3
  • 24
  • 42

1 Answers1

1
if os.path.isfile(image_1_path) == True:
   image_1 = PythonMagick.Image(image_1_path)
   image_combine = composite_images(image_combine, image_1, image_1_x, image_1_y)

The statements are indented by 3 spaces. Make it 4, i.e.

if os.path.isfile(image_1_path) == True:
    image_1 = PythonMagick.Image(image_1_path)
    image_combine = composite_images(image_combine, image_1, image_1_x, image_1_y)
R. S. Nikhil Krishna
  • 3,962
  • 1
  • 13
  • 27
  • Well, thank you a lot, I'll try but how do you know it? Do you know some tools to correct indentation automatically? – lolyoshi Oct 21 '16 at 13:32
  • 1
    When using sublime text, 1) Remove all indentation everywhere by `Ctrl+A`, followed by `Shift+Tab` multiple times. 2) Select the portion that is inside the `if` block(which you want to indent), then press `Tab` to indent it properly – R. S. Nikhil Krishna Oct 21 '16 at 13:48
  • **This is wrong, and would only have fixed the problem by accident** (changing the indentation would involve taking care to make sure it's consistent). Four-space indent is not a requirement; that is just the convention agreed upon by the community. The code must have mixed tabs and spaces, or used a different amount of spaces for the two lines, in a way that is not replicated in the example in the OP. The canonical question for this issue is https://stackoverflow.com/questions/45621722, but OP did not show code that actually demonstrates an issue. – Karl Knechtel Jul 14 '23 at 20:32