Python Forum
syntax error near unexpected token - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: syntax error near unexpected token (/thread-17722.html)



syntax error near unexpected token - btom529 - Apr-21-2019

Hello! ultra noobie with all things programming and I am currently registered in an online python course. During the tutorials I got stuck when I was prompted to enter a line:

name="BRADY H".lower()
This happens in only Visual Studio Code

It is supposed to be an example of the various python functions you can use but when I use this or .upper() or .replace() or any of the other tutorial functions I keep getting the error

Error:
bash:syntax error near unexpected token `('
Also I have tried:

my_book="My favorite book is 'Tod Sawyer',".replace('Tod', 'Tom')
print(my_book)
but get the same error...
This happens in both the editor (Visual Studio Code) and the shell/terminal on my computer. Please help as I am eager to learn but feel I can't even get started!


RE: syntax error near unexpected token - Yoriz - Apr-21-2019

Doesn't look like there is anything wrong with the code posted.


RE: syntax error near unexpected token - btom529 - Apr-21-2019

Could it have to do with the PATH when python was installed then? I'm sorry I wish I could give you more information but this is all I have to work with and why I am here on the forums. Also thank you for reformatting my question for me, my apologies.

Also when the functions are typed out in Visual studio code they do not change color to cyan, as illustrated in most tutorials. I don't think this would be the issue as the shell has no problem with it.


RE: syntax error near unexpected token - ichabod801 - Apr-21-2019

Your error starts with 'bash,' so you seem to be running the code in the bash shell rather than in Python. If it only happens in Visual Studio, I would guess you don't have Visual Studio set up correctly to run Python code. However, I am not familiar with Visual Studio, and would have no idea how to fix that.


RE: syntax error near unexpected token - Yoriz - Apr-21-2019

Make sure you have the python extension installed


RE: syntax error near unexpected token - btom529 - Apr-21-2019

Thank you this information is very helpful. Hopefully it will give me enough to troubleshoot the issue through google. I have also verified that the python extension within VSC is installed and active