Skip to Content
用于 DevOps 的 Python
book

用于 DevOps 的 Python

by Noah Gift, Kennedy Behrman, Alfredo Deza, Grig Gheorghiu
May 2025
Intermediate to advanced
506 pages
6h 56m
Chinese
O'Reilly Media, Inc.
Content preview from 用于 DevOps 的 Python

第 1 章 DevOps 的 Python 基础知识

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

DevOps 是软件开发与信息技术运营的结合,在过去十年间一直是一个热门领域。软件开发、部署、维护和质量保证之间的传统界限已被打破,从而使团队更加一体化。Python 因其兼具灵活性、强大功能和易用性,无论是在传统信息技术运营领域还是 DevOps 领域,都一直是一种热门语言。

Python 编程语言于 20 世纪 90 年代初公开发布,用于系统管理。它在这一领域取得了巨大成功,并被广泛采用。Python 是一种通用编程语言,几乎用于所有领域。视觉特效行业和电影业对它青睐有加。最近,它已成为数据科学和机器学习(ML)领域的事实语言,并被用于从航空到生物信息学的各个行业。Python 拥有丰富的工具库,可以满足用户的各种需求。学习整个 Python 标准库(任何 Python 安装都附带的功能)将是一项艰巨的任务。而要学习使 Python 生态系统更加生动的所有第三方软件包,也将是一项艰巨的任务。好消息是,您不需要做这些事情。您只需学习 Python 的一小部分,就能成为一名强大的 DevOps 实践者。

在本章中,我们将借鉴数十年的 Python DevOps 经验,只教授您需要的语言元素。 这些是 Python DevOps 日常使用的部分。它们构成了完成任务的基本工具箱。一旦掌握了这些核心概念,您就可以添加更复杂的工具,这将在后面的章节中看到。

安装和运行 Python

如果您想尝试本概述中的代码,需要安装 Python 3.7 或更高版本(截至本文撰写时,最新版本为 3.8.0),并能访问 shell。在 macOS X、Windows 和大多数 Linux 发行版中,您可以打开终端应用程序来访问 shell。 要查看您使用的 Python 版本,请打开 shell 并键入python --version:

$ python --version
Python 3.8.0

Python 安装程序可以直接从Python.org 网站下载。或者,您也可以使用 Apt、RPM、MacPorts、Homebrew、Chocolatey 或其他软件包管理器。

Python Shell

运行 Python 的最简单方法是使用内置的交互式解释器。只需在 shell 中输入python 。然后就可以交互式运行 Python 语句。键入exit() 退出 shell。

$ python
Python 3.8.0 (default, Sep 23 2018, 09:47:03)
[Clang 9.0.0 (clang-900.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 2
3
>>> exit()

Python 脚本

Python 代码从扩展名为.py的文件中运行:

# This is my first Python script
print('Hello world!')

将代码保存到名为hello.py 的文件中。要调用该脚本,请在 shell 中运行python ,然后运行文件名:

$ python hello.py
Hello world!

Python 脚本是大多数 Python 生产代码的运行方式。

IPython

除了内置的交互式 ...

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

《Python 数据分析》第三版

《Python 数据分析》第三版

Wes McKinney
ppk on JavaScript

ppk on JavaScript

Peter-Paul Koch

Publisher Resources

ISBN: 9798341657380