Jump to content

Google Python tutorial uses syntax inconsistent with my IDE (VS Code)

nightmarevoid

I'm trying to brush up on python using Google's python tutorials and by doing the exercises in VS Code, but the syntax is inconsistent between google's code and what the IDE expects. I'm using python 3.9.6 as the interpreter.

 

take for instance print. Should be straight forward, but google doesn't use a lot of syntax that VS Code is expecting. for example

#google exercises are written as

print 'hello world'

#VS Code throws errors
#It says things like "declarations should be on a new line)
#the tool tip for print shows everything in parenthesis
#It expects

print('hello world')

This is pretty frustrating because I have to spend time debugging google's own code. The worst part is that I'm not a big fan of google and wish they would do things differently, so spending time debugging their code while trying to use their resources is a level of cosmic irony I wasn't prepared for today.

 

to use python on VS code I'm using two extensions: "Python" by Microsoft and "Python Extension Pack" by Don Jayamanne

 

Is this discrepancy down to the python 3.9 interpreter being different, VS Code adding syntax where it isn't supposed to be, or google writing in an outdated form of Python? How can I fix it?

 

 

Ryzen 7 3700X

Aorus GTX 1080ti

G.Skill TridentZ 3200MHz 2x8GB

Corsair SFX 750W

Phanteks Evolve Shift Air (glass front)

2x Corsair Force GS 120GB SSD (RAID 0)

Link to comment
Share on other sites

Link to post
Share on other sites

Google's available code online is usually old.

 

The code you quoted is Python 2, so you need to use a python 2.7 interpreter instead of the 3.9.6 you're currently using.

FX6300 @ 4.2GHz | Gigabyte GA-78LMT-USB3 R2 | Hyper 212x | 3x 8GB + 1x 4GB @ 1600MHz | Gigabyte 2060 Super | Corsair CX650M | LG 43UK6520PSA
ASUS X550LN | i5 4210u | 12GB
Lenovo N23 Yoga

Link to comment
Share on other sites

Link to post
Share on other sites

34 minutes ago, nightmarevoid said:

I'm trying to brush up on python using Google's python tutorials and by doing the exercises in VS Code, but the syntax is inconsistent between google's code and what the IDE expects. I'm using python 3.9.6 as the interpreter.

 

take for instance print. Should be straight forward, but google doesn't use a lot of syntax that VS Code is expecting. for example



#google exercises are written as

print 'hello world'

#VS Code throws errors
#It says things like "declarations should be on a new line)
#the tool tip for print shows everything in parenthesis
#It expects

print('hello world')

This is pretty frustrating because I have to spend time debugging google's own code. The worst part is that I'm not a big fan of google and wish they would do things differently, so spending time debugging their code while trying to use their resources is a level of cosmic irony I wasn't prepared for today.

 

to use python on VS code I'm using two extensions: "Python" by Microsoft and "Python Extension Pack" by Don Jayamanne

 

Is this discrepancy down to the python 3.9 interpreter being different, VS Code adding syntax where it isn't supposed to be, or google writing in an outdated form of Python? How can I fix it?

 

 

You are probably following a python 2 tutorial, no parenthesis:

https://docs.python.org/2/tutorial/inputoutput.html

image.png.95c5969709f30e8d94d3955ae6ebb5e5.png

While in python 3 you should use parenthesis:

https://docs.python.org/3/tutorial/inputoutput.html
image.png.c522af3080476983150164ca79c468ae.png

 

Always check the official documentation when in doubt 🙂

 

VGhlIHF1aWV0ZXIgeW91IGJlY29tZSwgdGhlIG1vcmUgeW91IGFyZSBhYmxlIHRvIGhlYXIu

^ not a crypto wallet

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, nightmarevoid said:

print 'hello world'

this is the python 2 version, python 3 syntax is different.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Just so you know, your IDE has nothing to do with the syntax. The IDE uses pylint to lint your code, then VSCode looks for which version of Python you're using (bottom-left corner) to give pylint that version to lint. In other words, you can use Notepad to write code and use pylint to lint, it's still the same operation.

All IDEs do is to provide tools for programming languages, they aren't involved in the compilers/interpreters themselves.

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, Chubak said:

Just so you know, your IDE has nothing to do with the syntax. The IDE uses pylint to lint your code, then VSCode looks for which version of Python you're using (bottom-left corner) to give pylint that version to lint. In other words, you can use Notepad to write code and use pylint to lint, it's still the same operation.

All IDEs do is to provide tools for programming languages, they aren't involved in the compilers/interpreters themselves.

Mostly correct. The IDE having nothing to do with syntax isn't really true though, because the vast vast majority of them perform syntax highlighting and some have more advanced syntax-based features than that (e.g. identifying unused libraries that you've imported). So the IDE does need to know what syntax to expect to perform those functions in an effective manner.

____________________________________________________________________________________________________________________________________

 

 

____________________________________________________________________________________________________________________________________

pythonmegapixel

into tech, public transport and architecture // amateur programmer // youtuber // beginner photographer

Thanks for reading all this by the way!

By the way, my desktop is a docked laptop. Get over it, No seriously, I have an exterrnal monitor, keyboard, mouse, headset, ethernet and cooling fans all connected. Using it feels no different to a desktop, it works for several hours if the power goes out, and disconnecting just a few cables gives me something I can take on the go. There's enough power for all games I play and it even copes with basic (and some not-so-basic) video editing. Give it a go - you might just love it.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×