Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Visual Studio Code for Python Programmers
Visual Studio Code for Python Programmers
Visual Studio Code for Python Programmers
Ebook448 pages9 hours

Visual Studio Code for Python Programmers

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Become proficient and efficient with Visual Studio Code and learn how to integrate all your external tools!

Visual Studio Code for Python Programmers helps Python developers become not just familiar, but productive in Visual Studio Code. To start, you’ll find the steps for installing Visual Studio Code on Windows, Mac and Linux platforms, along with an introduction to the editing features of the workspace. Coverage of more advanced functionality includes managing source code, debugging, unit testing, and Jupyter Notebook support. The book finishes with a walk-through of real-world projects which utilize Visual Studio Code features introduced in the book.

For developers, the choice of an editor is a very personal one. You have idiosyncratic needs and wants that are unique to you as a developer. This book will help you learn how to customize Visual Studio Code to meet your needs and Python development workflow.

  • Introduces you to the features of the Visual Studio Code workspace and how those features can be customized
  • Demonstrates how Visual Studio Code allows you to choose your structure according to your needs
  • Covers editing code in Python, including syntax highlighting, code completion, object definition, refactoring, and code navigation
  • Describes Git integration and how to perform common Git functions (commits, checkouts, branches, and merges) from within Visual Studio Code
  • Highlights debugging features for Python developers
 A final section on Real World Applications will step you through several examples (and features integration with Django, Flask, Jupyter Notebook, Docker, and Azure), so you can hit the ground running with Visual Studio Code.
LanguageEnglish
PublisherWiley
Release dateJun 4, 2021
ISBN9781119773375
Visual Studio Code for Python Programmers

Related to Visual Studio Code for Python Programmers

Related ebooks

Programming For You

View More

Related articles

Reviews for Visual Studio Code for Python Programmers

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Visual Studio Code for Python Programmers - April Speight

    Introduction

    What started as an announcement at Microsoft Build 2015 has evolved into the Most Popular Development Environment, as ranked in the 2019 Stack Overflow Developer Survey. Visual Studio Code is a free, open-source, cross-platform code editor developed by Microsoft as part of the Visual Studio family. In comparison to its Visual Studio counterpart, Visual Studio Code is a streamlined code editor for a quick code-build-debug cycle. This feature-rich editor includes support for code completion, refactoring, formatting, managing source code, collaboration, debugging, unit testing, and more.

    This book introduces Visual Studio Code through the lens of a Python developer. Editor features are introduced and explored with examples applicable to Python development. The goal of this book is to help acclimate you to Visual Studio Code features and to help you develop an efficient development workflow.

    Stay up-to-date with new Visual Studio Code and Python features by visiting the Microsoft Developer Blog at devblogs.microsoft.com/python.

    Who Will Benefit Most from This Book

    Those who are in search of a comprehensive introduction to Visual Studio Code for Python development will benefit most from reading this book. It was written for developers with a working knowledge of Python. Although this book does not provide instruction for learning Python development, it includes general programming concepts, such as managing source control, unit testing, and debugging to name a few, which are explored as they relate to Visual Studio Code features. Python tools and libraries that fall outside of the Python Standard Library are also explored and provided with a foundational understanding to complete the exercises throughout this book.

    Looking Ahead in This Book

    Here's the book at a glance:

    Chapter 1: Getting Started introduces the Visual Studio Code interface and the Extension Marketplace. Instructions on how to customize the editor are provided, alongside keyboard shortcuts for quickly executing commands. The keyboard shortcuts are also provided, following the convention of iOS/Windows and Linux (e.g., Cmd+C/Ctrl+C is the shortcut to Copy).

    Chapter 2: Hello World for Python prepares your workspace for Python development. After installing a Python interpreter and the Python extension for Visual Studio Code, you are tasked to create and run your first Hello World program in the editor.

    Chapter 3: Editing Code explores standard Visual Studio Code editing features in addition to features provided by the Python extension.

    Chapter 4: Managing Projects and Collaboration discusses how to open and navigate files in addition to collaborating with others in Visual Studio Code. An introduction to managing Python environments is also provided as it relates to global, virtual, and conda environments.

    Chapter 5: Debugging takes you beyond print statements and instead shows you how to use the built-in debugger. Instructions for configuring the debugger are provided as well.

    Chapter 6: Unit Testing explains how to create, run, and debug unit tests within the Test Explorer. Examples are provided for both the unittest and pytest frameworks.

    Chapter 7: Jupyter Notebook introduces Jupyter Notebook support in Visual Studio Code. Learn how to create, edit, and run cells within the editor. An overview of how to debug a notebook and connect to a remote are provided as well.

    Chapter 8: Using Git and GitHub with Visual Studio Code explains how to extend your GitHub workflow in the editor without navigating to the browser. The GitHub Pull Requests and Issues extension is installed and used to maintain source code within a GitHub repository.

    Chapter 9: Deploy a Django App to Azure App Service using the Azure App Service Extension takes you through the basic workflow of creating a Django app and how to deploy to Azure within the editor.

    Chapter 10: Create and Debug a Flask App provides instruction for how to debug a website created with Flask in Visual Studio Code.

    Chapter 11: Create and Deploy a Container with Azure Container Registry and Azure App Service takes you through the basic workflow of containerizing a project with the Visual Studio Code Docker extension.

    Chapter 12: Deploy an Azure Function Trigger by a Timer explains how to create a daily RSS feed summary using a function created with Azure Functions that is deployed to Azure.

    Special Features

    The project files for this book are found on the book page at www.wiley.com. Each chapter introduction states which folder to refer to for the project file(s) required to complete the exercises.

    NOTE Boxes like this are used to expand on some aspect of the topic, without interrupting the flow of the narrative.

    How to Contact Wiley

    Wiley strives to keep you supplied with the latest tools and information you need for your work. If you believe you have found an error in this book, and it is not listed on the book's web page, you can report the issue to Wiley Customer Technical Support at wileysupport@wiley.com.

    Part I

    Welcome to Visual Studio Code

    In This Part

    Chapter 1: Getting Started

    Chapter 2: Hello World for Python

    Chapter 3: Editing Code

    CHAPTER 1

    Getting Started

    When you began your Python development journey, you were most likely introduced to Python's Integrated Development and Learning Environment (IDLE). IDLE's simplicity is ideal for newcomers but leaves much to be desired by those who are more comfortable with the language and are in need of an efficient and productive workflow. A range of code editors and integrated development environments (IDEs) are available for Python development—some for general development with multilanguage support (such as Atom or Sublime) and others built exclusively for Python (such as PyCharm). Selecting a development environment is a matter of personal preference. As an experienced programmer, you might have already tried a few editors and thus are aware of what features you most desire. If you're in need of an extensible code editor that provides ample flexibility, efficiency, and productivity for managing Python source code, then Visual Studio Code is well worth your consideration.

    Visual Studio Code (also referred to as VS Code) is a free, open-source, and cross-platform code editor developed by Microsoft. Ranked as the Most Popular Development Environment in the 2019 Stack Overflow Developer Survey, Visual Studio Code is a feature-rich highly customizable code editor that not only is great for editing source code but has built-in support for collaboration and cloud-hosted environments. Visual Studio Code's source code is available in the product's GitHub repository at github.com/microsoft/vscode. You're welcome to contribute to the project and can also view the product roadmap within the repository. Visual Studio Code is updated monthly with new features and bug fixes. For early adopters, the VS Code Insiders build provides a new build at least every day with features and bug fixes.

    Visual Studio Code has built-in support only for JavaScript, TypeScript, HTML, and CSS, but it supports many additional languages, such as Python, through extensions. Before you begin programming in Python, you must install the extension. You can then begin to familiarize yourself with the editor's interface within the context of Python.

    Installing Visual Studio Code

    As a free, cross-platform code editor, Visual Studio Code runs on macOS, Linux, and Windows. Download Visual Studio Code from code.visualstudio.com. If the browser doesn't detect your operating system, visit code.visualstudio.com/#alt-downloads for more options. Platform-specific installation steps are available at code.visualstudio.com/docs/setup/setup-overview. Both macOS and Windows provide the option to add Visual Studio Code to your PATH environment variable. Adding Visual Studio Code to your PATH environment variable provides the convenience of opening a folder directly from the console using the command code or code. (to open the current folder).

    As mentioned, Microsoft releases a new version of Visual Studio Code often with new features and important bug fixes. If your platform supports auto-updating, Visual Studio Code prompts you to install the new release when it becomes available. As an alternative, you can manually check for updates by running Help ➪ Check For Updates on Linux and Windows or by running Code ➪ Check For Updates on macOS.

    NOTE If you're interested in trying the VS Code Insiders build, you can download a copy from code.visualstudio.com/insiders/. You can install the Insiders build side by side with the latest monthly build, which enables you to use both versions of the code editor independently.

    The Visual Studio Code User Interface

    Visual Studio Code's user interface (UI) provides a simple minimal layout that keeps your source code as the focus of the development environment. When you first start Visual Studio Code, it displays a default layout. Each time you start Visual Studio Code going forward, the editor opens in the same state it was in when last closed.

    You can make yourself at home by customizing the layout to your liking. However, before you start moving things around, you should get to know the main areas of the UI and their respective function (see Figure 1.1).

    Snapshot of the Visual Studio Code user interface.

    Figure 1.1: The Visual Studio Code user interface.

    Activity Bar

    The Activity Bar, located on the far-left side, lets you switch between views. Views provide quick access to common tasks such as the following:

    Explorer—File and folder management

    Search—Global search and replace across open folders using plain text or regular expressions

    Source Control—Git source control for maintaining code repositories

    Run—Features used during debugging, such as variables, call stacks, and breakpoints

    Extensions—Browsing, installation, and management of extensions from the Extension Marketplace

    In addition to the default views, the Activity Bar can also include custom views provided by extensions that you install from the Extension Marketplace. Each view has an icon that reflects its respective function.

    You can reorder views by dragging and dropping them in the Activity Bar. Views can also be hidden if you right-click the view and select Hide From Activity Bar. Views are part of your custom layout that is preserved each time you run Visual Studio Code.

    Side Bar

    The Side Bar, located to the right of the Activity Bar, displays the active view. If no view is selected, the Side Bar is collapsed. You can resize the Side Bar by clicking and dragging the edge that it shares with the editor. The default views for the Side Bar are Explorer, Search, Source Control, Run, and Extensions (see Figures 1.2 through 1.6, respectively).

    Snapshot of explorer view.

    Figure 1.2: Explorer view.

    Snapshot of search view.

    Figure 1.3: Search view.

    Snapshot of source Control view

    Figure 1.4: Source Control view.

    Snapshot of run view

    Figure 1.5: Run view.

    Snapshot of extensions view

    Figure 1.6: Extensions view.

    Editor

    The editor, which fills most of the screen, is where you edit files. You can resize the editor by clicking and dragging the edges that it shares with the Side Bar and the panels.

    The top editor region can change depending on the type of file that's active in the editor. For example, if you edit a Markdown file, a Preview icon appears, thus enabling Visual Studio Code's Markdown Preview (see Figure 1.7).

    Snapshot of in the top image, the Preview icon appears in the top editor region since a Markdown file is opened. Clicking the icon displays a preview of the Markdown file, as shown in the bottom image.

    Figure 1.7: In the top image, the Preview icon appears in the top editor region since a Markdown file is opened. Clicking the icon displays a preview of the Markdown file, as shown in the bottom image.

    When you open a Python file, you instead see a Run Python File In Terminal icon (displayed as a Play button) in the top editor region. (The Run Python File In Terminal icon is a quick way for you to run a Python program.) When selected, a terminal opens, and the Python file is run (see Figure

    Enjoying the preview?
    Page 1 of 1
    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy