惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
美团技术团队
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
有赞技术团队
有赞技术团队
GbyAI
GbyAI
宝玉的分享
宝玉的分享
腾讯CDC
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
月光博客
月光博客
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) Top 15 Reinforcement Learning Questions That Will Appear in Exams The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How Python Borrows Other People's Work
Akhilesh · 2026-04-20 · via DEV Community

You have been writing everything yourself from scratch.

Every function, every loop, every piece of logic. That is exactly right for learning. But out in the real world, nobody builds everything from zero.

Python has been around since 1991. In that time, developers have written and shared hundreds of thousands of packages. Tools for working with data. Tools for making web requests. Tools for generating random numbers. Tools for working with dates. Tools for training neural networks.

All of it free. All of it one command away.

Knowing how to find, install, and use other people's code is one of the most valuable skills you will develop. This post is where that starts.


The Standard Library: Already Installed

Python ships with a large collection of built-in modules called the standard library. You do not need to install them. They are already there.

import brings a module into your file.

import math

print(math.pi)
print(math.sqrt(16))
print(math.ceil(4.2))
print(math.floor(4.9))

Enter fullscreen mode Exit fullscreen mode

Output:

3.141592653589793
4.0
5
4

Enter fullscreen mode Exit fullscreen mode

math is a module. A module is just a Python file with useful functions inside it. When you write import math, Python finds that file and makes everything in it available under the math. prefix.


More Standard Library Modules Worth Knowing

import random

print(random.randint(1, 10))        # random integer between 1 and 10
print(random.choice(["a", "b", "c"]))   # random item from a list
numbers = [1, 2, 3, 4, 5]
random.shuffle(numbers)
print(numbers)                       # list in random order

Enter fullscreen mode Exit fullscreen mode

Output (yours will differ, it's random):

7
b
[3, 1, 5, 2, 4]

Enter fullscreen mode Exit fullscreen mode

import datetime

today = datetime.date.today()
print(today)

now = datetime.datetime.now()
print(now)

Enter fullscreen mode Exit fullscreen mode

Output:

2024-11-15
2024-11-15 14:32:07.482910

Enter fullscreen mode Exit fullscreen mode

import os

print(os.getcwd())              # current working directory
files = os.listdir(".")         # list files in current folder
print(files)

Enter fullscreen mode Exit fullscreen mode

os is important for file system work. Checking if paths exist, creating folders, listing directory contents. You'll use it a lot when building data pipelines.


Importing Specific Things

Sometimes you only need one function from a module. No need to import the whole thing.

from math import sqrt, pi

print(sqrt(25))
print(pi)

Enter fullscreen mode Exit fullscreen mode

Output:

5.0
3.141592653589793

Enter fullscreen mode Exit fullscreen mode

Now you call sqrt directly without math. in front. Cleaner for functions you use constantly.

You can also give imports a shorter name.

import numpy as np
import pandas as pd

Enter fullscreen mode Exit fullscreen mode

You haven't installed these yet but when you do, this is how every single tutorial and professional uses them. np for NumPy. pd for Pandas. It is so universal that using any other name would confuse people reading your code.


pip: Installing Packages From the Internet

The standard library is big but it doesn't have everything. The Python Package Index, PyPI, hosts over 500,000 additional packages contributed by developers worldwide.

pip is the tool that downloads and installs them.

Open your terminal. Not inside Python. Your regular terminal or VS Code's integrated terminal.

pip install requests

Enter fullscreen mode Exit fullscreen mode

That's it. Python downloads the requests package and installs it. Now you can use it in any Python file on your machine.

Try a few packages that you'll use constantly in this series.

pip install requests
pip install numpy
pip install pandas
pip install matplotlib

Enter fullscreen mode Exit fullscreen mode

Each one downloads and installs. Takes a few seconds each.

Now use requests to make a real web request.

import requests

response = requests.get("https://api.github.com")
print(response.status_code)
print(type(response.json()))

Enter fullscreen mode Exit fullscreen mode

Output:

200
<class 'dict'>

Enter fullscreen mode Exit fullscreen mode

Your Python code just talked to GitHub's server and got a response back. Status code 200 means success. The response came back as a dictionary. Real data from the real internet.


Virtual Environments: Keep Projects Separate

Here is a problem that will bite you eventually.

Project A needs version 1.0 of some package. Project B needs version 2.0 of the same package. If you install packages globally, one of those projects breaks.

Virtual environments solve this. Each project gets its own isolated space with its own packages.

python -m venv myenv

Enter fullscreen mode Exit fullscreen mode

This creates a folder called myenv with a complete isolated Python installation inside.

Activate it:

# Windows
myenv\Scripts\activate

# Mac and Linux
source myenv/bin/activate

Enter fullscreen mode Exit fullscreen mode

Your terminal prompt changes to show the environment name. Now any pip install goes into that environment only, not the global Python.

When you're done:

deactivate

Enter fullscreen mode Exit fullscreen mode

For every serious project you start from this series onward, create a virtual environment first. It is a small habit that prevents big headaches.


requirements.txt: Sharing Your Setup

When you share a project with someone or deploy it to a server, they need to know which packages to install.

requirements.txt is the standard way.

pip freeze > requirements.txt

Enter fullscreen mode Exit fullscreen mode

This saves every installed package and its version to a text file. Open it and it looks like this:

numpy==1.26.0
pandas==2.1.1
requests==2.31.0
matplotlib==3.8.0

Enter fullscreen mode Exit fullscreen mode

Anyone who gets your project runs one command to install everything at once:

pip install -r requirements.txt

Enter fullscreen mode Exit fullscreen mode

Start doing this now. Even for small projects. It is a professional habit that costs nothing.


Writing Your Own Module

Any Python file you write is a module that other files can import.

Create a file called helpers.py:

def greet(name):
    return f"Hello, {name}!"

def add(a, b):
    return a + b

PI = 3.14159

Enter fullscreen mode Exit fullscreen mode

Now in a different file in the same folder:

import helpers

print(helpers.greet("Alex"))
print(helpers.add(5, 3))
print(helpers.PI)

Enter fullscreen mode Exit fullscreen mode

Output:

Hello, Alex!
8
3.14159

Enter fullscreen mode Exit fullscreen mode

Python found helpers.py in the same folder and imported everything from it. Your own reusable code, organized into modules, is how larger programs stay manageable.


Try This

Create modules_practice.py.

Part one: use the random module to build a simple dice roller. Roll two dice, each between 1 and 6. Print the result of each die and the total. Run it five times using a loop to make sure randomness is working.

Part two: use the datetime module to print today's date in a nice readable format like "Today is November 15, 2024." Look up strftime to format it properly. The search term is "python datetime strftime format codes."

Part three: create a file called calculator.py with four functions: add, subtract, multiply, and divide. Import that file in modules_practice.py and use each function at least once.

Part four: if you haven't already, install requests using pip and make a GET request to https://jsonplaceholder.typicode.com/users/1. Print the name and email from the response. It comes back as a dictionary.


What's Next

Phase 1 is almost done. Two more posts left. Next is list comprehensions, a cleaner way to build lists that you will see everywhere in Python code and will want to use immediately once you understand it.