Python Forum
VS Code from start
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VS Code from start
#2
Look at some useful features.

Format code
Before i did mention to install:
pip install autopep8 yapf black
Take a look at format code with the new star Black.
So right click and Format Document,after have choose "python.formatting.provider": "black"
Here a image on how it work have a long line with dict,list and tuple,right side after format.
[Image: 6jVJhv.jpg]
Mess up some code before and after format.
Messed up:
import random
import time

class Coin:
    def __init__(self ):
      self.sideup="Heads"

    def toss(self):
            if random.randrange( 2)== 0: 
              self.sideup =  "Heads"
            else:
              self.sideup= "Tails"

def toss_result(  ):
  my_coin=Coin( )
  print(f"This side is up: {my_coin.sideup}")
  print("I am tossing the coin...")
  time.sleep(4)
  my_coin.toss()
  print(f"This side is up: {my_coin.sideup}")

if __name__ == "__main__" :
  toss_result( )
After format:
import random
import time

class Coin:
    def __init__(self):
        self.sideup = "Heads"

    def toss(self):
        if random.randrange(2) == 0:
            self.sideup = "Heads"
        else:
            self.sideup = "Tails"

def toss_result():
    my_coin = Coin()
    print(f"This side is up: {my_coin.sideup}")
    print("I am tossing the coin...")
    time.sleep(4)
    my_coin.toss()
    print(f"This side is up: {my_coin.sideup}")

if __name__ == "__main__":
    toss_result()

IntelliSense
One of the strong feature with editor is IntelliSense
It goes beyond auto completion.
You can view available methods, parameter hints, short documentation, source code(where is function/method source code) etc...
If take mouse over get() method:
[Image: oJhIIU.jpg]
Need to scroll method doc or that it stay open ctrl+space.
Now can also look at source code for this get() function alt+f12(peek).
F12 goes to source code where get() is defined.

Linter
You annoying friend pylint Wall
pip install pylint flake8
So i turn it of in normal use,then just turn it on if want a check of code.
Command Palette ctrl+shift+p search Pylint then get an option on/off.
So how dos it work:
[Image: 8IpV89.jpg]
What it finds is down in left corner errors and Warnings .
Click on it and it show up in windows under.
So the fix is pretty obvious missing {.
print(f"This side is up: {my_coin.sideup}") 
Save and this error/advise goes away.
Reply


Messages In This Thread
VS Code from start - by snippsat - Aug-16-2018, 01:34 PM
RE: VS Code from start - by snippsat - Aug-18-2018, 08:49 PM
RE: VS Code from start - by snippsat - Aug-24-2018, 10:23 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020