Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
Python语言及其应用(第2版)
by
Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from
Python语言及其应用(第2版)
176
|
第
11
章
└
critters
└
rougarou.py
如果
north
和
south
均位于模块搜索路径内,则可以导入这些模块,就好像它们仍然位于单
一目录的包中那样。
from critters import wendigo, rougarou
11.2.4
模块和对象
什么时候该把代码放入模块?什么时候该把代码放入对象?
两者在许多方面看起来很相似。对于包含名为
stuff
的内部数据的对象或模块
thing
,其
数据可以使用
thing.stuff
访问。
stuff
可以在创建模块或类时定义,也可以随后赋值。
模块中的所有类、函数和全局变量都可以在外部访问。对象可以使用属性和双下划线命名
方式隐藏或控制对于其数据特性的访问。
这意味着可以这样做:
>>> import math
>>> math.pi
3.141592653589793
>>> math.pi = 3.0
>>> math.pi
3.0
我们刚刚是把这台计算机上的数学工具毁掉了吗?不是。这不会影响
Python
的
math
模块。
我们只是修改了程序所导入的
math
模块代码副本中的
pi
值,程序结束之后,一切改动就
都消失无踪了。
程序导入的模块只有一份副本,即便多次导入。你可以用它来保存导入该模块的代码感兴
趣的全局内容。这就像是类,同样只有一份副本,但可以由此创建多个对象。
11.3 Python
标准库
Python
的著名主张之一是“自备电池”
2
——
一个庞大的标准模块库,可用于完成大量实用
任务。标准库被分开存放,以免造成核心语言臃肿。当你着手编写 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial
You might also like
Python编程入门与实战
Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南
Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程
保罗·J·戴特尔
Python面向对象编程指南
Posts & Telecom Press, Steven F. Lott
Publisher Resources
ISBN: 9787115586223