Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp 3.0.4 python batch interpreter oddities
#2
I get the very same behavior if use:
Code:
>python3 -c 'a="something";if True: print(a);'
 File "<string>", line 1
   a="something";if True: print(a);
                 ^^
SyntaxError: invalid syntax

(and same behavior as with Gimp for the first case, too).

I think  you are misunderstanding the power of the semicolon in Python, it is not fully equivalent to a line feed. I refer you to the doc:

Quote:A suite is a group of statements controlled by a clause. A suite can be one or more semicolon-separated simple statements on the same line as the header, following the header’s colon, or it can be one or more indented statements on subsequent lines.
(Emphasis mine)

In other words, you can use the semicolon to make a one-liner with several assignments or even function calls (simple statements), but you cannot separate an if clause (compound statement)  from the rest with a semicolon.

Note however that the conditional assignment (Python's equivalent to the ternary operator in C) in a simple statement. So while you cannot write:

Code:
condition=True; if condition: x=foo ; else x=bar; print(x)

you can write:

Code:
condition=True; x="foo" if condition else "bar"; print(x)
Reply


Messages In This Thread
RE: Gimp 3.0.4 python batch interpreter oddities - by Ofnuts - 08-09-2025, 01:04 PM

Forum Jump: