Brother Wei's Private Python Recipes cover

Brother Wei's Private Python Recipes

No rating yet
Word count
29K words
Chapters
20

Tags

Summary

Weige's Python Home Cooking is a Python tips book by Wang Wei (online handle "Weige"), drawn from his own programming practice and published by China Machine Press in 2014. Rather than a step-by-step beginner's tutorial, it gathers the "home recipes" he uses repeatedly in daily work into a collection of short pieces—Python's readability, ease of learning and maintenance, portability, and cross-platform nature distilled into small solutions readers can copy directly. At roughly 29,000 Chinese characters, the book is compact, with each entry titled by the problem it solves. Topics include join/split and fixed-length splitting of strings, common list and array operations, time and date calculations, frequently used methods in the os.path module, reading configuration with ConfigParser, several ways to execute system commands, centralized try exception handling, string encryption and decryption, and on Windows, retrieving system information via WMI, playing warning sounds with winsound, and the wx.Frame window framework, as well as writing Python scripts to deploy the zabbix client, automatically add and remove hosts, monitor database ports for multiple instances on a single machine, clean up expired cron jobs on Linux, and recursively traverse directories and files. Overall it reads more like a work notebook to flip through—suited to readers with some foundation who need to look things up on the fly, a desk reference rather than a systematic textbook.

Editor's review

这本书的定位很特别:它不是又一本从变量、循环讲起的 Python 入门书,而是一个在机房里摸爬滚打多年的运维型开发者的“私房笔记”。书名里的“私房菜”三个字用得贴切——20 来个条目,每条对应一个真问题:监控端口、部署 zabbix 客户端、清理 crontab 里的过期任务、用 winsound 让脚本“叫”出来报警。写法直给,先摆问题再贴代码,不绕弯子,适合当你手边已经有一个具体任务、想快速找一条可改可用的参考时翻开。它的短板同样明显:篇幅只有两万多字,缺少完整的函数说明和章节体系,条目之间也没有循序渐进的知识框架,更像速查册而非教材;由于成书于 2014 年,示例多为 Python 2 时代写法,不少模块用法今天已被更新或替代,照抄前需要对照当前版本改写。如果你已经有 Python 基础,需要一个“别人是怎么干的”的参照,这本书仍有翻阅价值;如果你是零基础找系统教程,请另选一本正经的入门书,把这本书当补充案例来读。

Who it's for

A good fit for

  • 已有 Python 基础、需要随手查阅实用写法的开发者
  • 从事运维或系统管理工作、常写自动化脚本的工程师
  • 需要参考 zabbix、cron、系统信息采集类脚本的读者
  • 喜欢“短条目+示例代码”速查式阅读的技术爱好者

Not a good fit for

  • 完全没有编程经验、需要系统入门教程的零基础读者
  • 希望学习现代 Python 3 工程实践与规范的读者
  • 需要深度学习某一主题(如 Web、数据分析)的读者

Reading tips

  1. 先通读目录,把条目按自己的工作任务挑出来读,不必从头顺读。
  2. 示例多为 Python 2 时代写法,照抄前先在 Python 3 环境下试跑并核对模块。
  3. 读每条时补上官方文档中的函数说明,把它当引子而不是最终答案。
  4. 把与自己工作相关的脚本整理进个人代码库,边改边积累成自己的“私房菜”。

About the publisher

China Machine Press China · Founded in 1950

In addition to science and technology and professional publishing, the books in our catalog from China Machine Press also reflect a sustained focus on psychology, computing, management, finance and economics, and social sciences. In psychology, the catalog includes works by C. G. Jung and introductions to analytical psychology, as well as applied topics such as stress and health, and addiction and healing. In computing, it features Structure and Interpretation of Computer Programs (JavaScript Edition). Management and finance titles include Administrative Behavior (4th Edition), The Price of Inequality (Collector's Edition), and This Time Is Different: Eight Centuries of Financial Folly (Commemorative Edition). In the philosophy and history of science, there is The Worldview: The Third Edition. Relevant authors include C. G. Jung, William McGuire, Sonu Shamdasani, and Gabor Maté. Public information is limited; the above summarizes the publisher's profile based solely on the books in our catalog.

Contents

  1. Book Introduction
  2. Common Uses of join and split in Python
  3. A Summary of Common Time and Date Function Calculations in Python
  4. A Collection of Common Operations for Python Lists and Arrays
  5. Examples of Common Methods of the Python ConfigParser Module
  6. A Detailed Guide to Common Methods of the python os.path Module
  7. Several Common Ways to Execute System Commands in Python
  8. A Python Script for Deploying the zabbix Client on Windows
  9. A Summary of String Encryption and Decryption Methods in Python
  10. Common Concentrated Ways to Handle Program Exceptions with try in Python
  11. Monitoring Database Ports for Multiple Database Instances on a Single Machine with Python
  12. A Summary of 12 Common Basics in Python Programming
  13. Upper- and Lowercase Conversion for Strings in Python
  14. A Python Script for Automatically Adding and Removing Hosts in zabbix
  15. Splitting Python Strings by Fixed Length
  16. A Python Script to Clear Expired Scheduled Tasks in Linux cron
  17. Using the WMI Module to Obtain Windows System Information in Python
  18. Recursively Traversing All Files in a Directory
  19. The wx.Frame Framework Properties of python wx
  20. Implementing Sound in a Python Alarm Program with winsound

FAQ

这本书适合零基础学 Python 吗?
不太适合。全书是技巧短文合集,跳过基础语法,也不讲函数体系。零基础读者建议先读完一本系统入门教材,再回来看它当案例补充。
书中代码现在还能直接运行吗?
很多不能直接用。本书 2014 年出版,示例多为 Python 2 写法,print、除号、部分库接口等与 Python 3 不同,需按当前版本改写并核对模块是否仍在维护。
这本书有多少字、篇幅大吗?
掌阅等电子书平台标注约 2.9 万字,实体与电子版本都很薄,属于短篇合集,一两个晚上就能翻完。
和常见 Python 入门书有什么区别?
入门书按语法体系循序渐进;本书按“遇到的问题”组织,条目之间无递进关系,更像运维开发者的工作笔记,供需要时查阅。
哪里能买到正版?
该书由机械工业出版社出版,纸质版印量有限,建议在京东、当当、出版社官方渠道按书名与作者核对版本;也可留意掌阅等平台的授权电子版。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

About the author

王伟 Author

Wang Wei is an author whose works span several fields; public information about him is limited, and details such as his life story and nationality remain unclear. Judging from the 65 titles held in the collection, his interests range across Eastern and Western philosophy, medicine, politics, culture, and documentary literature. Representative works include Chu Ci Collation and Notes and A Compilation of Scattered Chu Ci Materials from Successive Dynasties, reflecting his engagement with the textual study of the Chu Ci; Ling Shu Principles and Methods, Zhongjing Principles and Methods, and Illustrated Minimally Invasive Abdominal Surgery show his attention to traditional Chinese medical theory and surgery; The Prince, the third volume of the First Book to Understand the World Pattern, on China's periphery, and Epidemic and Social Contagion on Complex Networks further reveal a scope covering political thought, international affairs, and interdisciplinary research. Overall, his works combine textual compilation, knowledge popularization, and topical studies, offering reference for readers with different needs.

More by the same author

Top rated in the same category