
Visual Studio Code for Python Programmers
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
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.
More details
Other editions
Additional editions

Person
Content
- Cover
- Title Page
- Copyright Page
- About the Author
- About the Technical Editor
- Acknowledgments
- Contents at a Glance
- Contents
- Introduction
- Who Will Benefit Most from This Book
- Part 1 Welcome to Visual Studio Code
- Chapter 1 Getting Started
- Installing Visual Studio Code
- The Visual Studio Code User Interface
- Activity Bar
- Side Bar
- Editor
- Panels
- Status Bar
- Command Palette
- Extensions
- Customizations
- Settings
- Color Themes and Icons
- Keybindings
- Display Language
- Summary
- Chapter 2 Hello World for Python
- Installing a Python Interpreter
- macOS
- Linux
- Windows
- Installing the Python Extension for Visual Studio Code
- Creating a Python File
- Selecting an Interpreter
- Setting a Default Interpreter
- Selecting a Linter
- Editing a Python File
- Running a Python File
- Workflow Recap
- Summary
- Chapter 3 Editing Code
- Quick Fixes
- Code Completion, Definitions, and Declarations
- Formatting
- Edit Formatting Settings in the Settings Editor
- Edit Formatting Settings in settings.json
- Linting
- Enable and Disable Linting
- Run Linting
- Linting Settings
- Refactoring
- Extract Variable
- Extract Method
- Sort Imports
- Snippets
- Summary
- Part 2 Additional Visual Studio Code Features
- Chapter 4 Managing Projects and Collaboration
- Files and Folders
- Open a Project
- Navigate Files
- Search across Files
- Close a File or Folder
- Environments
- Virtual Environments
- Conda Environments
- Source Control
- Initialize a Repository
- Commit Changes
- Branches
- Remotes
- Gutter Indicators
- View Diffs
- Push and Merge Commits
- Pull Requests
- Live Share
- Install Live Share
- Sign In to Live Share
- Share a Project
- Join a Session
- Editing and Collaboration
- Summary
- Chapter 5 Debugging
- Starting a Debug Session
- Debug Commands
- Continue
- Step Over
- Step Into
- Step Out
- Stop
- Restart
- Call Stack
- Triggering a Breakpoint
- Logpoints
- Watch
- The Debug Console
- Launch Configurations
- Summary
- Chapter 6 Unit Testing
- Enable and Discover Tests
- Run Tests
- Debug Tests
- Summary
- Chapter 7 Jupyter Notebook
- Creating and Opening a Jupyter Notebook
- Code Cell Modes
- Adding Cells
- Editing Cells
- Running a Cell
- Running a Single Cell
- Running All Code Cells
- Running Cells Above and Below a Code Cell
- Additional Commands
- Viewing Variables and Data
- Viewing Plots
- Debugging a Jupyter Notebook
- Connecting to a Remote Server
- Exporting a Notebook
- Summary
- Chapter 8 Using Git and GitHub with Visual Studio Code
- Getting Started
- GitHub Pull Requests and Issues Extension
- Publish a Project to GitHub
- Push Changes to GitHub
- Manage Pull Requests and Issues
- Pull Requests
- Issues
- Clone Repository
- Timeline View
- Summary
- Chapter 9 Deploy a Django App to Azure App Service with the Azure App Service Extension
- Getting Started
- Creating a Django Project
- Creating an App
- Creating a Home Page
- Creating Website Pages
- Deploying to Azure
- Summary
- Chapter 10 Create and Debug a Flask App
- Getting Started
- Create a Flask App
- Create and Render a Template
- Debug the Flask App
- Summary
- Chapter 11 Create and Deploy a Container with Azure Container Registry and Azure App Service
- Getting Started
- Create a Container
- Add Docker Files to the Project
- Build an Image
- Build and Run a Container
- Debug a Container
- Push an Image to the Registry
- Create an Azure Container Registry
- Determine the Image's Registry Location
- Deploy the Container Image to Azure
- Make Changes to the App and Deploy
- Multicontainer Apps
- Summary
- Chapter 12 Deploy an Azure FunctionTrigger by a Timer
- Getting Started
- Create an Azure Function
- Invoke the Function Locally
- Add the Code to the Function
- Deploy the Function to Azure
- Summary
- Appendix: Getting Started with Azure
- Index
- EULA
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 <folder> 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).
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).
Figure 1.2: Explorer view.
Figure 1.3: Search view.
Figure 1.4: Source Control view.
Figure 1.5: Run 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).
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 1.8).
Figure 1.8: The Run Python File In Terminal icon displays at the top of the editor region. Clicking the icon runs the Python file.
For most file types, the top editor region also includes an Open Changes icon for viewing changes in the file since the last commit to source control (see Figure 1.9). Selecting the icon opens the Diffs editor (see Figure 1.10). The Diffs editor opens in a new tab with a side-by-side view of the diffs. You could also access the Diffs editor by selecting the file in the Source Control view.
Figure 1.9: When the Open Changes icon is clicked, a new tab opens that shows the diffs for the file.
Figure 1.10: The Diffs editor shows the changes made in the file since the last commit.
The region also contains a Split Editor Right icon for splitting the editor (see Figure 1.11). When selected, a new editor group opens to the right of the initial editor. You can open and modify files in either editor window.
Figure 1.11: When the Split Editor Right icon is clicked, a new editor group is opened to the right.
An opened and active file displays the source code in the middle of the editor, and a Minimap is located at the top right (see Figure 1.12). The Minimap provides a condensed miniature view of the entire file and is great for quick navigation and visually knowing where you are in the context of the entire file.
Figure 1.12: A Minimap displays at the right of the bankaccount.py file. You can click anywhere in the Minimap to quickly navigate to the code at that location.
You can open as many files as you like in the editor. Each opened file is distinguishable by a tabbed header. The active file is the file in which your cursor appears. You can drag tabs to reorder them and also pin tabs (Cmd+K Shift+Enter/Ctrl+K Shift+Enter1) to keep your most used files within reach. A pinned tab displays with the language icon for the respective file (see Figure 1.13).
Figure 1.13: The helloworld.py file is a pinned tab. A pin icon next to the filename in the tab indicates that...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.