Indentation error in scripts

Hi everyone,

I need help with how to get rid of indentation error that comes in script files for no reason.
I know that there should be no identation error but I get it. It does not go away very easily.
Here is a screenshot-
image

I have to try really hard sometimes to get rid of this.

It feels like it is a bug.
Any suggestion on getting rid of this issue permanently?

Thanks & regards,
Ajay Kumar Gupta

We can't tell without seeing the previous lines. If that's inside a function at the root level of the script and isn't nested under some other expression, then it is indented one too far.

1 Like

You are either indented to the wrong "level", or are using tabs and spaces interchangeably, which you can not do in Python. Post the whole scripts and we can help.

5 Likes

Right click in the editor space -> appearance -> whitespace. This should allow you to determine if you have mixed spaces and tabs. Also make sure you aren't missing any colons or brackets.

9 Likes

can you give us the actual scripts?

Yes, it is a bug in your code (which we are still waiting for). Please see Wiki - how to post code on this forum.

1 Like

I found this post after having a bunch of problems with this. The suggestion to turn on Whitespace was the game changer. It makes things much easier to fix once you get used to linking the clues to the proper corrective action. I have a fair amount of code pasted from chatgpt, which I think is what got my script editor so messed up. I’m wondering if others have linked the cause to pasting code from there.

Probably not, considering LLMs' poor performance with Ignition's niche jython usage.

(Do read the FAQ about posting LLM output here.)

1 Like

Agreed- The suggestion to turn on Whitespace was the game changer.
For me it is not copy paste.
It just happens. Even with the code that has been working. If i add a new line of code suddenly it starts erroring out. Especially if there is a commented line and i add a new line after that.
Just random.

I really doubt that the python editor somehow randomly starts misinterpreting indentation...

I seem to have random indentation issues periodically. It looks correct, but the error persists. I can fix one line, and the issue moves to another line. When this happens, I paste into VS code, nudge all code right and then back left, then paste back into Ignition.

1 Like

That’s exactly happens with my team as well.

Never seen that... But I do most coding in an external editor.