Hello VS code day. I'm Anthony Shaw and I'm going
to give you a tour of Python in VS code.
So for this talk there's a couple of things you'll
need.
First of all we need VS code so you can
get this from code.visualstudio.com.
The second thing you'll need once you've got Visual Studio
code downloaded is the Python extension and I'll also be
using some features from the pylon 6 tension,
which is an optional add on to the Python extension,
but something that you should definitely consider.
Once you've installed so once you open up VS code,
go to the extension panel on the left hand side
and then hit.
From here you can search for Python.
The Python extension will be right at the top and
then search for the pilots extension and click and install
that extension as well.
Once you've got those two extensions installed,
you'll also need a copy of Python on your local
computer.
One of the first things you'll need to do when
you open up.
An existing project or start a new project in Python
And you want to work with the Python extension is
to tell the extension which Python interpreter to use.
You can do this from the command palette if you
search for interpreter and you'll see the Python select interpreter
command.
As with all Python projects,
you should create a virtual environment 1st and install your
requirements into that virtual environment,
and there are some resources I can share on how
you would do that when you're working with imported modules
types classes.
Functions anything in Python. The Python extension is going to
give you a lot of information as you're coding,
and you'll see that as I'm typing,
the Python extension is giving me suggestions about functions,
attributes, or types that belong in that namespace.
There's a couple of things you can do to make
navigation a lot easier inside your code base.
For example, in this views file I'm working on some
specific classes.
If I hover over those,
I can see just the docstrings,
so the information that's been provided.
By the Django project about what that class is,
if I hold down on my either the Alt key
on Windows and Linux or the Mac Key on Mac
OS,
if I hover over that class,
you'll also get both the docstring and the class that
information,
so I can see a bit more context about what's
happening with that class.
You can also use that to,
then click on the class and it will navigate to
that from either the package that you're using or from
your own code.
You can also right click on a function.
A method or a class,
or even a variable that you define in your Python
code and do find all references and it will navigate
through your code base and find where you've included that
function where you've called that function,
and you can use that as a shortcut to then
navigate and find different areas where it's being used.
Something else that you get from Vscode isn't integrated terminal,
so from the terminal menu,
if you open up a new terminal,
if you have the Python extension installed,
it will automatically activate the virtual environment.
When you open up any additional terminals,
now you can run Python code from the terminal as
you would do in any environment.
But to get the full debugger capabilities,
you're going to want to configure a launch profile.
So if you go to the run and debug button
on the left hand side in VS code,
then click run and debug,
you're going to get a wizard to help you navigate
through what it is that you want to debug.
In my case, I'm working on a Django app,
but there are configuration so fast,
API, flask, and pyramid. If you're working on a standalone
Python script,
then pick the Python file option,
or if you're working on an installable module,
you can pick the module option.
If you select Django, it's going to know automatically what
commands to run inside the virtual environment once you've launched
your project inside the debugger,
you'll get access to the full debugger set up.
This includes both being able to configure a specific breakpoints
in your code,
navigating variables information, and then also in the debug console.
You can type anything that you would normally add a
rapport,
so if you wanted to get information about specific types
in a breakpoint or you wanted to force a break
point or catch any uncaught exception,
and then handle that directly in the editor,
you can do that using this navigation.
So that's my quick tour of the Python extension for
VS code and what you can do.
Both coding, navigating, debugging and testing Python code inside the
Python extension.
So to recap everything we've gone through,
you'll need VS code. You'll need a copy of Python
installed on your local machine,
and you'll need both the Python extension for VS code
and the pilots extension for VS code.
Every time you open up a project,
you'll need to make sure that you select the interpreter.
That information does get saved,
so if you reopen the same project.
Or remember which interpreter you used.
Thanks for attending VS Code day.
I'm Anthony Shaw and if you have any questions please
give me a shout.