Fundamentals 7 min read

Boost Your Python Workflow: Sublime Build System, iTerm2 Image Viewer, and Typing Tricks

This article introduces three handy tools—a Sublime Text build system for running Python scripts, an iTerm2 imgcat utility for displaying images directly in the terminal, and a concise guide to Python's typing module with practical code examples.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost Your Python Workflow: Sublime Build System, iTerm2 Image Viewer, and Typing Tricks

This article presents three useful utilities that can improve your development efficiency: enabling Python execution in Sublime Text, viewing images directly in iTerm2 on macOS, and an overview of Python's typing module.

Enable Python execution in Sublime Text

To run Python scripts from Sublime Text, open ToolsBuild SystemNew Build System... and replace the default content with the following JSON configuration:

{
    "cmd": ["D:/Anaconda3/python3.7.exe", "-u", "$file"]
}

Save the file, then open a Python script (e.g., test.py) and press Ctrl+B or select Tools → Build to execute it. The output will appear in the Sublime console.

View images directly in iTerm2 on macOS

The iTerm2 terminal supports inline image display via the imgcat utility. Create a shell script named imgcat.sh following the instructions at iTerm2 imgcat , make it executable with chmod u+x imgcat.sh, and then run the script to display images in the terminal.

Python typing module overview

The typing module provides optional type hints for Python code, enabling static type checking, improving documentation, and offering non‑intrusive runtime warnings.

Type checking to prevent mismatched parameter and return types.

Documentation aid for developers.

Does not affect program execution; only provides hints.

Example: a function that sums the digits of a numeric string.

from typing import *

def digits_sum(num: str) -> int:
    digits_arr = map(lambda x: int(x), num)
    return sum(digits_arr)

num = "352"
result = digits_sum(num=num)
print(result)  # 10

Another example: a function that multiplies numeric values in a dictionary by two.

from typing import Dict, Any

def dict_multipy(d: Dict[str, Any]) -> Dict[str, float or int]:
    new_dict = {}
    for k, v in d.items():
        if isinstance(v, (float, int)):
            new_dict[k] = v * 2
    return new_dict

d = {"no": "100", "age": 12, "work_year": 3, "name": "JC"}
new_d = dict_multipy(d=d)
print(new_d)  # {'age': 24, 'work_year': 6}

Creating type aliases, e.g., defining Vector as List[float] and a scaling function:

from typing import List

Vector = List[float]

def scale(scalar: float, vector: Vector) -> Vector:
    return [scalar * num for num in vector]

new_vector = scale(2.0, [1.0, -4.2, 5.4])
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

typingSublime Textcode-snippetsiTerm2imgcatdevelopment-tools
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.