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

推荐订阅源

Hacker News - Newest:
Hacker News - Newest: "LLM"
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
N
News and Events Feed by Topic
T
Troy Hunt's Blog
PCI Perspectives
PCI Perspectives
W
WeLiveSecurity
N
News | PayPal Newsroom
Recent Commits to openclaw:main
Recent Commits to openclaw:main
V2EX - 技术
V2EX - 技术
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threat Research - Cisco Blogs
L
LINUX DO - 热门话题
Cloudbric
Cloudbric
S
Secure Thoughts
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
Y
Y Combinator Blog
L
LangChain Blog
Recorded Future
Recorded Future
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
Attack and Defense Labs
Attack and Defense Labs
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
小众软件
小众软件
H
Hacker News: Front Page
The Hacker News
The Hacker News
T
Tailwind CSS Blog
The Register - Security
The Register - Security
Hacker News: Ask HN
Hacker News: Ask HN
P
Privacy & Cybersecurity Law Blog
P
Palo Alto Networks Blog
S
Securelist
腾讯CDC
雷峰网
雷峰网
G
Google Developers Blog
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
P
Privacy International News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
Arctic Wolf
www.infosecurity-magazine.com
www.infosecurity-magazine.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
AI
AI

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) How Python Borrows Other People's Work 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 Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Quark's Outlines: Python Name Spaces
Mike Vincent · 2026-05-02 · via DEV Community

Quark’s Outlines: Python Name Spaces

Overview, Historical Timeline, Problems & Solutions

An Overview of Python Name Spaces

What is a Python name space?

When you write code in Python, you give names to values. A Python name space is the place where those names are stored. It is like a labeled shelf that holds objects. When you ask for a name, Python looks in the shelf to find it.

A name space is a mapping between names and objects. In Python, that mapping is usually a dictionary. Each name space stores the current known names and their values.

Python lets you manage names by storing them in name spaces.

x = 5
print(globals()["x"])
# prints:
# 5

Enter fullscreen mode Exit fullscreen mode

The globals() function returns the current global name space. You can look up a name and find its value.

How many name spaces does Python use?

Python uses three main name spaces when running code: local, global, and built-in. Each one is searched in order when Python tries to find a name. Local is the first shelf. Global is the next shelf. Built-in is the last shelf.

Each function or block of code runs in its own execution frame. The frame sets the local and global name spaces.

Python searches for names in a fixed order: local, global, built-in.

def demo():
    x = 10
    print(locals()["x"])

demo()
# prints:
# 10

Enter fullscreen mode Exit fullscreen mode

Here, locals() returns the local name space of the demo() function. Python found the name x there.

How do names become local or global?

When Python sees a name, it decides if that name is local or global by looking at how you use it. If you assign a value to the name in a code block, Python makes it local. If you use global, Python treats it as global. The same rule applies to nonlocal for nested functions.

You cannot assign to a global name without saying so. You must declare it first with global.

Python lets you control where a name lives using global or nonlocal.

count = 0

def add():
    global count
    count += 1

add()
print(count)
# prints:
# 1

Enter fullscreen mode Exit fullscreen mode

Without the global statement, the name count would be treated as a new local name and not affect the global value.


A Historical Timeline of Python Name Spaces

Where do Python’s name space rules come from?

Python name spaces follow from long traditions in structured programming. They help manage how values are stored and found. This timeline shows how Python shaped its name space model by building on earlier systems and simplifying control.


People designed scope and name systems in programming

1960 —Block scope in ALGOL introduced local variables and nested name visibility.

1972 —Global and local stacks in C separated function-level and file-level scope.


People built Python’s three-level name space model

1991 —Python 0.9.0 introduced global, local, and built-in name spaces tied to execution frames.

2000 —Dynamic features like exec and eval worked with customizable name space dictionaries.

2003 —Global and nonlocal statements became required to rebind outer names safely.

2010 —Function scoping stabilized with improved shadowing rules and traceability.

2025 —Stable execution model kept the name space structure clear and unchanged.


Problems & Solutions with Python Name Spaces

How do you use Python name spaces the right way?

Python uses name spaces to keep values organized while code runs. Each code block runs inside a frame, and each frame has local and global name spaces. These problems show how name spaces affect what Python sees and what it cannot see.


Problem: How do you modify a name in the outer scope in Python?

You define a value and use it inside a function. But when you run the function, Python says the name does not exist. You expected Python to use your global variable, but it made a new local one.

Problem: You want to share a name between a function and the outer scope.

Solution: Python lets you mark the name as global to make it refer to the same value everywhere.

Python lets you bind names to global space using global.

counter = 0

def step():
    global counter
    counter += 1

step()
print(counter)
# prints:
# 1

Enter fullscreen mode Exit fullscreen mode

Without the global line, Python would raise an error because counter += 1 would try to read an uninitialized local name.


Problem: How do you see what names are in use in Python?

You are writing a function that changes many variables. You want to see what names are active inside the function as it runs. You also want to inspect the global names.

Problem: You want to examine the current local and global name spaces.

Solution: Python provides locals() and globals() to return the current mappings.

Python lets you see active names using built-in inspection tools.

x = 100

def report():
    y = 200
    print("Local:", locals())
    print("Global:", "x =", globals()["x"])

report()
# prints:
# Local: {'y': 200}
# Global: x = 100

Enter fullscreen mode Exit fullscreen mode

Python shows the two separate name spaces so you can know which values are in each.


Problem: How do you avoid accidental name changes in Python?

You write a helper function that uses the same name as one of your main program variables. Now your main value is changed unexpectedly after calling the helper.

Problem: You want to keep helper names separate from program names.

Solution: Python keeps local name spaces separate by default. Avoid global names inside functions unless needed.

Python keeps function names isolated using local name spaces.

value = "main"

def helper():
    value = "helper"
    print("Inside:", value)

helper()
print("Outside:", value)
# prints:
# Inside: helper
# Outside: main

Enter fullscreen mode Exit fullscreen mode

Each block has its own space. Reusing a name locally does not affect the global value unless you declare it as global.


Problem: How do you use eval() safely in Python?

You want to evaluate a string as code. You want to control what names the string sees when it runs.

Problem: You want to give custom name spaces to code run with eval().

Solution: Python lets you pass dictionaries to control global and local name spaces in eval().

Python lets you set name space mappings for dynamic code.

scope = {"x": 2, "y": 3}
print(eval("x * y", scope))
# prints:
# 6

Enter fullscreen mode Exit fullscreen mode

The string "x * y" is evaluated using the custom scope dictionary. Python does not use the default globals or locals.


Problem: handle name lookup when a name is missing

You write code that refers to a name, but you forget to define it. When Python runs, it stops with an error. You want to understand what error this is and how Python looks for names.

Problem: You want to know what happens when a name is not found.

Solution: Python looks in local, then global, then built-in name spaces. If no match is found, it raises a NameError.

Python raises an error when name lookup fails in all name spaces.

try:
    print(missing_name)
except NameError as e:
    print("Caught error:", e)
# prints:
# Caught error: name 'missing_name' is not defined

Enter fullscreen mode Exit fullscreen mode

Python checks each shelf of names in order. If the name is not on any shelf, it stops and reports the problem.


Like, Comment, Share, and Subscribe

Did you find this helpful? Let me know by clicking the like button below. I'd love to hear your thoughts in the comments, too! If you want to see more content like this, don't forget to subscribe. Thanks for reading!


Mike Vincent is an American software engineer and app developer from Los Angeles, California. More about Mike Vincent