Can someone figure out why this is improperly indented?

29 views
Skip to first unread message

Paul Camp

unread,
Jun 16, 2025, 6:35:01 PMJun 16
to glowscri...@googlegroups.com
Web VPython 3.2
from visual import *

#make two objects

redbox = box(pos=vec(0,0,-1), size = vec(5, 5, 0.5), color = color.red, opacity = 0.4)
particle = sphere(pos=vec(-5, 0, -5), radius = 0.3, color = color.cyan, make_trail = True)

#initialize variables; create a new velocity property for the particle object

particle.v = vec(0.5, 0, 0.5)
dt = 0.05
t=0

#animation loop

while t <10:
    print(t)
    t = t + dt

This came from a much longer program. Every time it griped about a line being improperly indented, I removed that line. The complaint then moved backward to the previous line. If I have a while and a time increment, it is happy. If I put anything in between, it is improperly indented.

--
Dr. Paul J. Camp

"The beauty of the cosmos derives not only from unity in variety
       but also from variety in unity"
                 -- Umberto Eco
                     The Name of the Rose

Steve Spicklemire

unread,
Jun 16, 2025, 6:44:25 PMJun 16
to 'Jim D.' via Glowscript Users, Steve Spicklemire
I’m not sure I understand. I copy/pasted your code, as is, and it runs without complaint.

Are you saying that with the print statement there it fails for you?
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/glowscript-users/CAKdMb%3DzLJk-UrBQs8K0Y32bs%2BVHn_Wb-5YqjGG1OM4ti1zzT-A%40mail.gmail.com.

Paul Camp

unread,
Jun 16, 2025, 7:01:52 PMJun 16
to glowscri...@googlegroups.com
It does. It gives an inconsistent indentation on line 19 error. That is the line with the print. 

Here's a direct link:


Max DeMarr

unread,
Jun 16, 2025, 8:06:03 PMJun 16
to glowscri...@googlegroups.com

On line 20 of your code you linked, I see a double indented line "t = t + dt". However, from your first message, it seems that there is some more holistic problem you are working on?


Steve Spicklemire

unread,
Jun 16, 2025, 8:55:38 PMJun 16
to 'Jim D.' via Glowscript Users, Steve Spicklemire
I checked in a text editor that shows invisible characters, and I see there’s a single tab character on line 20. Did you edit your code originally in a different editor?

PastedGraphic-2.png

Paul Camp

unread,
Jun 16, 2025, 9:13:38 PMJun 16
to glowscri...@googlegroups.com
It isn't my code. It is a student's. I was trying to figure out why it won't run when everything looks properly indented. I've only edited it in the Glowscript editor. I assume my student did the same though I don't know that for sure.


On Mon, 16 Jun 2025 at 20:55, Steve Spicklemire <stevespi...@gmail.com> wrote:
I checked in a text editor that shows invisible characters, and I see there’s a single tab character on line 20. Did you edit your code originally in a different editor?

--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.


--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.

Steve Spicklemire

unread,
Jun 16, 2025, 9:21:44 PMJun 16
to glowscri...@googlegroups.com, glowscri...@googlegroups.com
I see. I’ll look into implementing some kind of warning about mixed tabs and spaces.

thanks,
-steve

On Jun 16, 2025, at 9:13 PM, Paul Camp <pjc...@gmail.com> wrote:



Harlan Gilbert

unread,
Jun 17, 2025, 4:15:57 AMJun 17
to glowscri...@googlegroups.com
1) The linked version is different than the version you pasted.

2) All the lines Inside the while loop must have the same indentation.  This is not the case in your program (linked version)


Harlan Gilbert, Ph.D.
High School Math, Physics, Computer Science, and Philosophy Teacher
Collegium Chair
Green Meadow Waldorf High School
Chestnut Ridge, NY 10977


Paul Camp

unread,
Jun 17, 2025, 6:55:02 PMJun 17
to glowscri...@googlegroups.com
Odd. I see a single indented line. But in the student's code, it never even got that far before saying improper indention.

Paul Camp

unread,
Jun 17, 2025, 6:56:15 PMJun 17
to glowscri...@googlegroups.com
I stripped down the student code to essentials. It works unless there is something between the while and the t increment.

On Mon, 16 Jun 2025 at 20:06, Max DeMarr <maxd...@gmail.com> wrote:

Steve Spicklemire

unread,
Jun 17, 2025, 7:10:09 PMJun 17
to 'Jim D.' via Glowscript Users, Steve Spicklemire
You could use an editor that shows invisible characters, or an online invisible character viewer, like this:

https://invisiblecharacterviewer.com/

Paste your code in, and see if there is any enlightenment.
> To view this discussion visit https://groups.google.com/d/msgid/glowscript-users/CAKdMb%3DxvTu0pi9jsXPrMSK9HK1SdVRExQGWyDqKLg%3D9FKyqv9w%40mail.gmail.com.

Steve Spicklemire

unread,
Jun 17, 2025, 7:12:54 PMJun 17
to 'Jim D.' via Glowscript Users, Steve Spicklemire
Also, if you use the arrow keys to move around, even in the WebVPython editor, you can find a tab by noting when cursor jumps four spaces with a single horizontal arrow key press.

Harlan Gilbert

unread,
Jun 17, 2025, 7:13:41 PMJun 17
to glowscri...@googlegroups.com
It seems that different browsers display the hidden tab character differently.  On some of them, the double indent appears while on others the line looks to be indented just as the others are. 

The display of the line has nothing to do with the interpretation of the line, which throws an error on all browsers.


Harlan Gilbert, Ph.D.
High School Math, Physics, Computer Science, and Philosophy Teacher
Collegium Chair
Green Meadow Waldorf High School
Chestnut Ridge, NY 10977

Harlan Gilbert

unread,
Jun 17, 2025, 7:15:25 PMJun 17
to glowscri...@googlegroups.com
This is because if there's just a single line of indented code, Python doesn't care how much it's indented.  If there are multiple lines, however, they must all be indented the same amount.


Harlan Gilbert, Ph.D.
High School Math, Physics, Computer Science, and Philosophy Teacher
Collegium Chair
Green Meadow Waldorf High School
Chestnut Ridge, NY 10977

Paul Camp

unread,
Jun 17, 2025, 7:50:06 PMJun 17
to glowscri...@googlegroups.com
That's a handy tool. But it doesn't show anything except carriage return/line feeds. I used the original student program, as far as she got with it.

Paul Camp

unread,
Jun 17, 2025, 8:07:04 PMJun 17
to glowscri...@googlegroups.com
Well isn't that interesting. The invisible character viewer didn't see any tabs in my stripped down code. But because I don't have anything else to do right now, I tried to run it again and it worked. However, the student's original code still does not work and still says there is an indentation error on line 19, where she set the frame rate. I'm attaching the invisible character output here. I notice that the line #move the particle and subsequent lines seem to be indented differently from the frame rate line, but they don't look that way on Glowscript. However, I also don't see a tab for those two rate lines so I'm wondering if she did those with spaces.
Screenshot 2025-06-17 200032.png
Message has been deleted

Steve Spicklemire

unread,
Jun 17, 2025, 8:50:15 PMJun 17
to 'Jim D.' via Glowscript Users, Steve Spicklemire
Aha. As Harlan pointed out, the issue is that you have different indention in the same scope. I would vote to replace every tab with four spaces.

PastedGraphic-1.png
Message has been deleted

Paul Camp

unread,
Jun 17, 2025, 8:52:28 PMJun 17
to glowscri...@googlegroups.com
But if I copy and paste the student's code, all the lines after the while appear to be indented with tabs, but it still says incorrect indent on the frame rate line. If I comment out that line, the indent error moves to the position update line.

I'm baffled.

Steve Spicklemire

unread,
Jun 17, 2025, 9:00:30 PMJun 17
to 'Jim D.' via Glowscript Users, Steve Spicklemire
I can only say that if it appears to be indented correctly, but you’re getting an indention error, it’s almost certainly a tab fouling things up somewhere.

I’m not sure what else to say! If you have a program that’s not working this way, you can send me the link off-list and I can try to help you track it down.
> To view this discussion visit https://groups.google.com/d/msgid/glowscript-users/CAKdMb%3Dx6AcxVaBdMyzE6Awnibv5u0Sne86ygYdmroN8gFcybKQ%40mail.gmail.com.


Paul Camp

unread,
Jun 17, 2025, 9:01:17 PMJun 17
to glowscri...@googlegroups.com
Those spaces delete as a single character, not four of them. I did think of that and tried deleting all the indents and then putting back an appropriate number of tabs. That didn't fix it. But when I tried your suggestion, replacing tabs with four spaces, the program runs. This is curious. I also tried deleting each line back to the previous line, hitting enter, and letting it indent itself. That didn't work either. I always thought it required tabs, not spaces.

On Tue, 17 Jun 2025 at 20:50, Steve Spicklemire <stevespi...@gmail.com> wrote:
Aha. As Harlan pointed out, the issue is that you have different indention in the same scope. I would vote to replace every tab with four spaces.

--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.


--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.

Paul Camp

unread,
Jun 17, 2025, 9:02:11 PMJun 17
to glowscri...@googlegroups.com
Thanks for your help everyone!
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages