-4

So yes I know that there is an answer on how to fix this but can someone explain to me what the hell it means?Because I don't know where it comes from and I also don't know what indented means in programming (as you can understand dear reader English is not my native tongue).

P.S I found that error from a for-loop I was trying to execute, and the code was similar to this:

img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS)
j='.jpg'
s='somepic'
p=img.save(s+'1'+j)

   for i in range(2, 659):
    if i==21:
     i = i + 1
    elif i==36:
     i=i+1
    elif i==45:
     i = i + 1
    elif i==51:
     i = i + 1
    elif i==133:
     i = i + 1
    elif i==163:
     i = i + 1
    elif i==263:
     i = i + 1
    elif i==267:
     i = i + 1
    elif i==272:
     i = i + 1
    elif i==299:
     i = i + 1
    elif i==300:
     i = i + 1
    elif i==312:
     i = i + 1
    elif i==313:
     i = i + 1
    elif i==314:
     i = i + 1
    elif i==320:
     i = i + 1
    elif i==323:
     i = i + 1
    elif i==362:
     i = i + 1
   elif i==390:
     i = i + 1
   elif i==432:
     i = i + 1
   elif i==445:
     i = i + 1
   elif i==455:
     i = i + 1
   elif i==459:
     i = i + 1
   elif i==460:
     i = i + 1
   elif i==461:
     i = i + 1
   elif i==477:
     i = i + 1
   elif i==487:
     i = i + 1
   elif i==493:
     i = i + 1
   elif i==496:
     i = i + 1
   elif i==500:
     i = i + 1
   elif i==510:
     i = i + 1
   elif i==519:
     i = i + 1
   elif i==522:
     i = i + 1
   elif i==545:
     i = i + 1
   elif i==547:
     i = i + 1
   elif i==562:
     i = i + 1
   elif i==597:
     i = i + 1
   elif i==599:
     i = i + 1
   elif i==615:
     i = i + 1
   elif i==638:
     i = i + 1
   elif i==654:
     i=i+1
   else:
     p= img + "i".save(s+i+j)
     i=i+1

Which means a for-loop, an if-statement, a couple of elifs (or ORs inside the first if-statement) and then I am closing my if-statement with a save and a step forward.

EDITED: So the code above is what I have written and before that are a bunch of image inputs.But although I manage to fix the code with what you said at the end I have another error which says ['str' object has no attribute 'save'] but that is a problem for another time.

Ka_Papa
  • 137
  • 9
  • `i=2` is unnecessary – Vaibhav Bajaj Aug 01 '16 at 20:50
  • 3
    `if [i=21]:` isn't valid Python. – ArtOfWarfare Aug 01 '16 at 20:51
  • neither is `elif i=36:`. – bgporter Aug 01 '16 at 20:52
  • "Indented", in this context, means added whitespace characters at the beginning of each line, which Python uses during parsing to determine the scope of structures like if statements and for loops. – Jim Lewis Aug 01 '16 at 20:53
  • @OP: You write "the code was similar to this". Why don't you show us the real code which gives you the problem? – Matthias Aug 01 '16 at 21:43
  • @OP Because I did not have the code at the moment.Either way Jim Lewis answerd to my question, but I will post the code just to see what I have written so you can help me more efficiently (because then I will have both the correct code and the explanation why my code had errors) – Ka_Papa Aug 02 '16 at 05:33
  • *"I also don't know what indented means"* Then you should learn - understanding indentation is fundamental to coding in Python. A quick google of "Python Indentation" brings a list of references, any one of which would tell you what you need to know. – SiHa Aug 02 '16 at 07:27
  • Yes, I understand what you are saying, but I also said "English is not my native tongue", I also respect the rules that this site has, so as you can understand, I have googled the word and I know what it means, but more often than not to understand the meaning of the word you need to see where it comes from as well as the use of it. Now I know what it means as well as it's nature in Python – Ka_Papa Aug 02 '16 at 07:36

2 Answers2

0

In python syntax, if statements, loops, and functions must be followed by indented lines. It's just python syntax. You have to put 4 spaces or use a tab before each line to indent them. In many other scripting languages, { } are used to enclose the code blocks. Without correct indenting, python doesn't know when a block of code ends.

Arush Shah
  • 17
  • 1
  • 4
  • "You have to put 4 spaces ..." is wrong. According to the [**Style Guide for Python Code**](https://www.python.org/dev/peps/pep-0008/) you _should_ use 4 spaces for each level of indentation. – Matthias Aug 01 '16 at 21:42
-1

An indent in Python is 4 spaces. Would have commented this, but I don't have enough reputation. Here's a link: Python: using 4 spaces for indention. Why?

Community
  • 1
  • 1
Pine
  • 104
  • 1
  • 6
  • No, the indent can be any number of spaces or tabs. 4 is just convenient or conventional, and recommended by the style guide PEP-8 https://www.python.org/dev/peps/pep-0008/ . – user1016274 Aug 03 '16 at 08:39