Exercise 3.1: IndentationError

I tried to run the command

rosrun move_bb8_pkg move_bb8_square.py

However, I kept receiving an IndentationError

I double checked the python code multiple times using the PyCharm editor and there were no indentations in the code; specifically line 12. Any suggestions?

Hi @AhmedAltalag, welcome to the community!

This is probably an issue after pasting code in your script. If you share the program bellow, we will be able to spot the indentation error.

Another thing you can try and do is delete the file and start over so you can find the syntax error.

Take a full screenshot of the IDE with the file in it.

Before taking the screenshot, use the button in the top-right corner of the IDE to maximize it, and make sure we can see the line that allegedly has the indentation problem (line 12 in this case). See an example with another file below:

I did not open the IDE in this platform before now. I was trying to figure out how to fix the problem through the Bash. Once I opened the IDE, it turned out that the code is filled with indentation problems although I copied it directly from the lecture notes provided to me. I fixed all the errors and now it works just fine.

Thanks a lot for your help!

Glad you got it working!

Except specifically asked to use the web shell, please use the IDE for editing code, to make your life easier. Especially when you want to copy and paste!

Hi @AhmedAltalag ! It seems like you tried to copy from the lecture notes and paste into the vi editor as it auto-indents by default. Here is a tip- when you want to paste multiple lines, you can enter “Paste” mode by typing this when in you are in Command mode:

:set paste

Then when you want to go back to the default you can do:

:set nopaste

Source: https://stackoverflow.com/questions/31712737/inserting-text-in-vim-causes-each-line-to-be-shifted-right

1 Like

hey @AhmedAltalag, since you’ve used the vi editor through terminal for copy pasting this error took place. There is auto indentation in vi editor, you can avoid it by entering into paste mode and exiting it once pasting is done. You can also edit “.vimrc” file and set a hotkey for toggling between paste and no paste mode, but it’s to cumbersome and not really necessary. When I first learned about bash terminal and vi editor I used to have the terminal for writing and copy pasting code. But this is not recommended since you have the editor there, editor makes everything easy. Also you can see any kind of syntax error before even running the code which isn’t possible for vi editor.

Regards,
Arif

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.