Python Intermediate

01 - Welcome & Local Development Setup

Instructor and Course Overview

Welcome to Intermediate Python Programming for Research! This course is designed for researchers who have mastered the basics of Python and are ready to tackle more complex programming challenges. Whether you're building sophisticated data pipelines, developing custom analysis tools, or creating reusable research software, this course will elevate your Python skills to the next level.

As before, my name is Victor Gambarini. Having worked with Python for over a decade in both academic and production environments, I've seen firsthand how proper development practices can transform research workflows. This intermediate course builds on the foundation we established in the introductory course, but now we're moving beyond the training wheels of Colab into the professional world of local development.

Why Move to Local Development?

While Colab is excellent for learning and quick prototyping, serious Python development requires a more robust environment. In this course, you'll learn to work like professional developers and advanced researchers do - with full control over your environment, powerful debugging tools, and the ability to create complex, multi-file projects.

About This Course

Over the next five days, we'll transform you from a beginner Python user into a confident intermediate programmer. You'll learn industry-standard tools, best practices, and advanced techniques that will make your research code more reliable, maintainable, and powerful.

Course Structure

  1. Welcome & Local Development Setup - Professional Python environment with VS Code
  2. Virtual Environments & Package Management - Isolating and managing dependencies
  3. Advanced Data Structures & Algorithms - Beyond basic lists and loops
  4. Object-Oriented Programming for Research - Classes, inheritance, and design patterns
  5. Error Handling & Debugging - Writing robust, fault-tolerant code
  6. Advanced File Operations & APIs - Working with complex data sources
  7. Testing Your Research Code - Unit tests and validation frameworks
  8. Code Organization & Modules - Building reusable research libraries
  9. Performance Optimization - Making your code faster and more efficient
  10. Advanced Data Analysis Patterns - Complex pandas operations and data pipelines
  11. Creating Research Tools - Building command-line interfaces and utilities
  12. Documentation & Code Quality - Professional standards for research software
  13. Deployment & Sharing - Packaging and distributing your research tools
  14. Integration Project - Build a complete research application
  15. Advanced Resources - Pathways to expert-level development

What You'll Accomplish

By the end of this course, you'll be able to:

  • Set up and manage professional Python development environments
  • Write clean, maintainable, and well-tested research code
  • Create complex, multi-file Python projects
  • Debug and optimize your code effectively
  • Build reusable tools and libraries for your research
  • Follow software engineering best practices in research contexts
  • Collaborate effectively on code projects with version control

Prerequisites

This course assumes you have completed the introductory Python course or have equivalent experience. You should be comfortable with:

  • Basic Python syntax (variables, data types, functions)
  • Working with lists, dictionaries, and basic data structures
  • Using pandas for data manipulation
  • Creating basic plots with matplotlib
  • Understanding of loops and conditional statements

Why Use VS Code for Research

What is Visual Studio Code?

Visual Studio Code (VS Code) is a free, open-source code editor developed by Microsoft. It has become the most popular code editor among Python developers and researchers worldwide. Think of it as a supercharged text editor specifically designed for programming.

Why VS Code is Perfect for Research Programming

1. Powerful Code Intelligence

  • Intelligent code completion and suggestions
  • Real-time error detection and warnings
  • Advanced debugging capabilities with breakpoints
  • Integrated terminal for running commands

2. Extensive Python Support

  • Official Python extension with rich features
  • Jupyter notebook support within VS Code
  • Interactive Python REPL
  • Variable explorer and data viewer

3. Research-Friendly Features

  • Git integration for version control
  • Extension ecosystem for scientific computing
  • Markdown preview for documentation
  • LaTeX support for academic writing

4. Project Management

  • Workspace management for complex projects
  • File explorer with search capabilities
  • Multi-file editing and navigation
  • Integrated source control

5. Customization and Extensions

  • Thousands of extensions for specialized tasks
  • Customizable themes and layouts
  • Snippet management for repetitive code
  • Remote development capabilities

VS Code vs. Other Development Environments

Feature VS Code PyCharm Spyder Colab
Learning Curve Easy Steep Moderate Very Easy
Performance Fast Heavy Moderate N/A
Debugging Excellent Excellent Good Limited
Extensions Thousands Many Few None
Multi-language Yes Limited No Limited
Cost Free Paid/Free Free Free
Offline Work Yes Yes Yes No

Installing Python Locally

Step 1: Download Python

For Windows: 1. Visit python.org/downloads 2. Download the latest Python 3.11 or 3.12 version 3. Important: Check "Add Python to PATH" during installation 4. Choose "Install Now" for standard installation

For macOS: 1. Visit python.org/downloads 2. Download the macOS installer 3. Run the installer and follow the prompts 4. Alternatively, use Homebrew: brew install python

For Linux (Ubuntu/Debian): bash sudo apt update sudo apt install python3 python3-pip python3-venv

Step 2: Verify Installation

Open your terminal or command prompt and run:

bash python --version

or

bash python3 --version

You should see something like: Python 3.12.0

Step 3: Install pip (if not included)

Pip is Python's package installer. Verify it's installed:

bash pip --version

If not installed, download get-pip.py from bootstrap.pypa.io and run:

bash python get-pip.py

Common Installation Issues

Windows PATH Problems: - If Python commands don't work, you may need to add Python to your PATH manually - Search for "Environment Variables" in Windows settings - Add Python installation directory to PATH

Permission Issues on macOS/Linux: - Use python3 and pip3 instead of python and pip - May need to use sudo for system-wide installations

Multiple Python Versions: - Use python3.12 to specify exact version - Consider using pyenv for version management


Installing VS Code

Step 1: Download VS Code

  1. Visit code.visualstudio.com
  2. Download the installer for your operating system
  3. Run the installer and follow the setup wizard

Installation Tips: - Windows: Choose "Add to PATH" option - macOS: Drag VS Code to Applications folder - Linux: Use the provided .deb or .rpm package

Step 2: First Launch

  1. Open VS Code
  2. You'll see the Welcome tab with getting started information
  3. The interface consists of:
  4. Activity Bar (left): File explorer, search, source control, etc.
  5. Side Bar (center-left): Contents of selected activity
  6. Editor (center): Where you write code
  7. Terminal (bottom): Command line interface

Step 3: Essential Settings

Enable Auto Save: 1. Go to File > Preferences > Settings (or Ctrl + ,) 2. Search for "auto save" 3. Set Auto Save to "afterDelay"

Configure Terminal: 1. View > Terminal (or `Ctrl + ``) 2. Ensure it opens to your preferred shell


Installing Python Extension

Step 1: Open Extensions View

  1. Click the Extensions icon in the Activity Bar (or press Ctrl + Shift + X)
  2. Search for "Python"
  3. Look for the official "Python" extension by Microsoft

VS Code Python Extension

Step 2: Install the Extension

  1. Click "Install" on the Python extension
  2. VS Code will download and install the extension
  3. You may need to reload VS Code when prompted

Step 3: Configure Python Interpreter

  1. Open the Command Palette (Ctrl + Shift + P)
  2. Type "Python: Select Interpreter"
  3. Choose your installed Python version from the list
  4. VS Code will remember this setting for future sessions

Additional Useful Extensions

For Research and Data Science:

  1. Jupyter - Notebook support in VS Code
  2. Search for "Jupyter" and install the official extension
  3. Enables .ipynb file support

  4. Python Docstring Generator - Auto-generate documentation

  5. Helps write proper function documentation

  6. GitLens - Enhanced Git capabilities

  7. Advanced version control features

  8. Markdown All in One - Better markdown support

  9. For writing documentation and README files

  10. Python Type Hint - Better type checking

  11. Helps catch errors before runtime

Verifying Extension Installation

  1. Create a new file: File > New File
  2. Save it as test.py
  3. Type some Python code:
print("Hello, VS Code!")
x = [1, 2, 3, 4, 5]
print(sum(x))
  1. You should see:
  2. Syntax highlighting (colored code)
  3. Code completion suggestions
  4. A "Run Python File" button in the top-right corner

Your First Local Python Script

Step 1: Create a Project Folder

  1. Create a new folder on your computer called intermediate-python-course
  2. In VS Code, go to File > Open Folder
  3. Select your new folder
  4. VS Code will open with your folder in the Explorer

Step 2: Create Your First Script

  1. Right-click in the Explorer panel
  2. Select "New File"
  3. Name it hello_research.py
  4. Add the following code:

!/usr/bin/env python3

""" My first local Python script for research This script demonstrates basic Python setup verification """

import sys import platform from datetime import datetime

def system_info(): """Display system and Python information""" print("=" * 50) print("RESEARCH PYTHON ENVIRONMENT INFO") print("=" * 50)

print(f"Python Version: {sys.version}")
print(f"Platform: {platform.system()} {platform.release()}")
print(f"Current Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Script Location: {__file__}")

print("\nPython Path:")
for path in sys.path[:3]:  # Show first 3 paths
    print(f"  - {path}")

print("\nInstalled Packages Check:")
required_packages = ['pandas', 'numpy', 'matplotlib', 'seaborn']

for package in required_packages:
    try:
        __import__(package)
        print(f"  ✓ {package} - Available")
    except ImportError:
        print(f"  ✗ {package} - Not installed")

print("=" * 50)

if name == "main": print("Welcome to Intermediate Python for Research!") print("This script verifies your local development setup.\n")

system_info()

print("\nIf you see this message, your Python environment is working!")
print("You're ready to start building serious research tools! 🚀")

Step 3: Run Your Script

Method 1: Using VS Code's Run Button 1. Click the "Run Python File" triangle button in the top-right 2. Output will appear in the Terminal panel below

Method 2: Using the Terminal 1. Open the integrated terminal: View > Terminal 2. Type: python hello_research.py 3. Press Enter

Method 3: Using Command Palette 1. Press Ctrl + Shift + P 2. Type "Python: Run Python File in Terminal" 3. Press Enter

Step 4: Understanding the Output

Your script should display: - Python version information - Operating system details - Current timestamp - Available packages status

If any required packages are missing, don't worry - we'll install them in the next session!


Essential VS Code Features for Research

1. Integrated Terminal

The integrated terminal is one of VS Code's most powerful features:

  • Open Terminal: View > Terminal or Ctrl + `
  • Multiple Terminals: Click the + icon to create new terminals
  • Terminal Types: PowerShell, Command Prompt, Git Bash (Windows), or Bash/Zsh (macOS/Linux)

2. File Explorer and Search

  • Explorer Panel: View files and folders in your project
  • Quick Open: Ctrl + P to quickly open files by name
  • Search Across Files: Ctrl + Shift + F to search all files in your project

3. IntelliSense and Code Completion

  • Auto-completion: Type and press Tab to accept suggestions
  • Parameter Hints: See function parameters as you type
  • Quick Documentation: Hover over functions to see documentation

4. Debugging

  • Set Breakpoints: Click in the gutter next to line numbers
  • Start Debugging: F5 or Run > Start Debugging
  • Variable Inspection: View variable values while debugging
  • Call Stack: See the execution path

5. Git Integration

  • Source Control Panel: View > Source Control
  • Stage Changes: Click + next to modified files
  • Commit: Add message and commit changes
  • Push/Pull: Sync with remote repositories

6. Command Palette

The Command Palette (Ctrl + Shift + P) gives you access to all VS Code features:

  • Python: Run Python File in Terminal
  • Python: Select Interpreter
  • Format Document
  • Git: Clone
  • File: New File

7. Workspace Settings

Create project-specific settings:

  1. Create a .vscode folder in your project
  2. Add a settings.json file:

json { "python.defaultInterpreterPath": "./venv/bin/python", "python.linting.enabled": true, "python.linting.pylintEnabled": true, "python.formatting.provider": "black", "files.autoSave": "afterDelay", "files.autoSaveDelay": 1000 }


Quick Reference

Essential Keyboard Shortcuts

  • Ctrl + Shift + P: Command Palette
  • Ctrl + P: Quick File Open
  • F5: Start Debugging
  • `Ctrl + ``: Toggle Terminal
  • Ctrl + /: Toggle Line Comment
  • Shift + Alt + F: Format Document
  • Ctrl + Shift + X: Extensions View
  • Ctrl + Shift + G: Source Control
  • F12: Go to Definition
  • Ctrl + Space: Trigger IntelliSense

Python-Specific Shortcuts

  • Shift + Enter: Run Selected Lines in Terminal
  • Ctrl + F5: Run Without Debugging
  • F9: Toggle Breakpoint
  • F10: Step Over (debugging)
  • F11: Step Into (debugging)

File Operations

  • Ctrl + N: New File
  • Ctrl + S: Save File
  • Ctrl + Shift + S: Save As
  • Ctrl + O: Open File
  • Ctrl + K, Ctrl + O: Open Folder

Getting Help in VS Code

  • Help > Welcome: Getting started guide
  • Help > Interactive Editor Playground: Learn VS Code features
  • Command Palette > "Help": Access various help options
  • F1: Alternative to Command Palette

Troubleshooting Common Issues

Python Not Found: - Check if Python is in PATH - Use Command Palette: "Python: Select Interpreter" - Verify installation with python --version in terminal

Extensions Not Working: - Reload VS Code: Command Palette > "Developer: Reload Window" - Check extension is enabled in Extensions view - Look for error messages in Output panel

Terminal Issues: - Try different terminal type (PowerShell vs Command Prompt) - Check default terminal setting in preferences - Restart VS Code if terminal becomes unresponsive


What's Next?

In our next session, we'll dive into virtual environments and package management - crucial skills for managing complex research projects. You'll learn how to:

  • Create isolated Python environments for different projects
  • Install and manage packages with pip and conda
  • Handle dependency conflicts
  • Set up reproducible research environments

Make sure you can comfortably create Python files, run scripts, and navigate VS Code before we continue. The skills you've learned today form the foundation for everything we'll build in this intermediate course.

Homework

Before the next session:

  1. Practice with VS Code: Create a few Python files and get comfortable with the interface
  2. Explore Extensions: Browse the Extensions marketplace and install any that look useful
  3. Try the debugger: Set a breakpoint in your script and step through the code
  4. Check package installations: Note which packages are missing from the system check script

Remember: the transition from Colab to local development might feel overwhelming at first, but the power and flexibility you gain will transform your research workflow. You're now working with the same tools used by professional developers and advanced researchers worldwide!

Enjoying this course?

This is just the first episode! Register to unlock 0 more episodes and complete your learning journey.

Register for Full Course