LaTeX | 文档单位排版宏包选型与使用

注:本文为 “LaTeX | 文档单位排版” 相关讨论合辑。
英文引文,机翻未校。
如有内容异常,请看原文。


What package should I use to typeset units?

应该使用哪个宏包来排版单位?

I know there are a few packages related to typesetting units:
我知道有几个与单位排版相关的宏包:

  • unitsdef

    units, which can be seen as a “base package” used by unitsdef
    units,可视为 unitsdef 所依赖的“基础宏包”

  • SIunits

    siunitx, which is the successor to SIunits
    siunitx,是 SIunits 的后续版本

  • maybe others? like cjwunits and hepunits
    或许还有其他的?例如 cjwunitshepunits

What is the difference between them? Do they also work inside Math mode? And, more importantly, which one should I use?
它们之间有什么区别?在数学模式(Math mode)下是否同样适用?更重要的是,应该选择哪一个?

Suggestion for people trying to answer this question: show some examples of how to typeset both simple and complex units. For instance, try typesetting these items:
给试图回答这个问题的人的建议:展示一些简单和复杂单位的排版示例。例如,尝试排版以下内容:

  • 100 Celsius

  • 3 x 10^5 km/s

  • gravitational constant is measured in N m2/kg2

  • 10 kHz = 1 s^{-4}

  • sin(x) meters

\documentclass{article}
\usepackage{siunitx} % 加载单位排版宏包
\usepackage{amsmath} % 用于数学环境
\begin{document}

\begin{itemize}
\item 100 Celsius:\qty{100}{\degreeCelsius}
      % $100^\circ\text{C}$
      
\item $3 \times 10^5$ km/s:\qty{3e5}{\km\per\s}
      % $3 \times 10^5 \, \text{km/s}$
      
\item gravitational constant is measured in $\text{N}\,\text{m}^2/\text{kg}^2$:
      引力常量的单位为 \unit{\newton\metre\squared\per\kilogram\squared}
      % $\text{N}\,\text{m}^2/\text{kg}^2$
      
\item $10 \, \text{kHz} = 1 \, \text{s}^{-4}$:
      \( \qty{10}{\kilo\hertz} = \qty{1}{\per\second\tothe{4}} \)
      % $10 \, \text{kHz} = 1 \, \text{s}^{-4}$
      
\item $\sin(x)$ meters:\qty[parse-numbers = false]{\sin(x)}{\metre}
      % $\sin(x) \, \text{m}$
\end{itemize}

\end{document}

渲染效果
 
10 0 ∘ C 100^\circ\text{C} 100C
3 × 1 0 5   km/s 3 \times 10^5 \, \text{km/s} 3×105km/s
N   m 2 / kg 2 \text{N}\,\text{m}^2/\text{kg}^2 Nm2/kg2
10   kHz = 1   s − 4 10 \, \text{kHz} = 1 \, \text{s}^{-4} 10kHz=1s4
sin ⁡ ( x )   m \sin(x) \, \text{m} sin(x)m

I think these examples cover most needs when writing scientific texts: simple measurements (value + simple unit), values written in scientific notation, simple fractional units, complex fractional and squared units, units without any value accompanying them, units with arbitrary exponents, and arbitrary math code instead of a simple value.
我认为这些示例涵盖了撰写科学文献时的大部分需求:简单测量值(数值+简单单位)、科学计数法表示的数值、简单分数形式单位、复杂分数及平方形式单位、无伴随数值的单位、含任意指数的单位,以及用任意数学代码替代简单数值的情况。

edited Aug 24, 2010 at 11:45
Joseph Wright♦
asked Aug 24, 2010 at 11:34
Denilson Sá Maia

Answers

As the author of siunitx I have some idea about the relative strengths of the various alternatives. There are various things that need to be done for units:
作为 siunitx 宏包的作者,我对各类替代方案的相对优势有所了解。单位排版需要实现以下多项功能:

  • Semantic input of units, so \kilo\metre rather than km: this allows special effects such as reformatting fractions ‘on the go’ (some people prefer to use literal input, and this ideally needs to be supported too).
    单位的语义化输入,例如使用 \kilo\metre 而非 km:这支持即时重新格式化分数等特殊效果(部分用户倾向于使用字面输入,理想情况下也应支持该方式)。

  • Formatting of numbers, for example dividing up digits into groups.
    数值格式化,例如将数字分组显示。

  • Correctly presenting awkward symbols such as the micro symbol.
    正确呈现特殊符号(如微符号 μ)。

  • Setting the font: many guidelines call for units to be in upright roman font with no bold or italic variation.
    字体设置:许多规范要求单位使用直立罗马字体(upright roman font),不使用粗体或斜体变体。

  • Keeping numbers and units together (no space breaking)
    保持数值与单位的关联性(不允许换行分隔)

Many packages have been written to address one or other aspect of this question. For example, SIunits is good at providing semantic input, whereas SIstyle focusses on correct typesetting but leaves the input to the user. On the other hand, unitsdef sticks to doing only units and does not worry about other aspects.
已有多个宏包针对上述部分功能需求而开发。例如,SIunits 擅长提供语义化输入,而 SIstyle 专注于正确排版但将输入方式交由用户自行处理。此外,unitsdef 仅专注于单位相关功能,不涉及其他方面。

The aim of the siunitx package is to cover all of the requirements above, and to provide a way that package behaviour can be altered. Thus it uses a series of key-value options that will change how the output is formatted. The options can be applied to the entire document or to an individual piece of input. It also is designed to work in either math or text mode equally well. I have also been very careful to provide up to date advice about the internationally-agreed units in the documentation of siunitx.
siunitx 宏包的目标是覆盖上述所有需求,并提供可调整宏包行为的方式。为此,它采用一系列键值对选项来改变输出格式,这些选项可应用于整个文档或单个输入内容。该宏包同时设计为在数学模式和文本模式下均能良好工作,且其文档中包含了关于国际通用单位的最新建议。

As a demo, using the latest release of siunitx the following all show off the package:
以下是使用最新版本 siunitx 的演示示例,展示了该宏包的功能:

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\begin{itemize}
\item \qty{100}{\degreeCelsius}
\item \qty{3e5}{\km\per\s} or \qty[per-mode = symbol]{3e5}{\km\per\s}
\item \unit{\newton\metre\squared\per\kilogram\squared} or
\unit[per-mode = symbol]{\newton\metre\squared\per\kilogram\squared}
\item $\qty{10}{\kilo\hertz} = \qty{1}{\per\second\tothe{4}}$
\item \qty[parse-numbers = false]{\sin(x)}{\metre}
\end{itemize}

\end{document}

10 0 ∘ C 100^\circ\text{C} 100C
3 × 1 0 5   km   s − 1  or  3 × 1 0 5   km/s 3 \times 10^5 \, \text{km}\,\text{s}^{-1} \text{ or } 3 \times 10^5 \, \text{km/s} 3×105kms1 or 3×105km/s
N   m 2   kg − 2  or N   m 2 / kg 2 \text{N}\,\text{m}^2\,\text{kg}^{-2} \text{ or } \text{N}\,\text{m}^2/\text{kg}^2 Nm2kg2 or Nm2/kg2
10   kHz = 1   s − 4 10 \, \text{kHz} = 1 \, \text{s}^{-4} 10kHz=1s4
sin ⁡ ( x )   m \sin(x) \, \text{m} sin(x)m

There are a couple of notes to bear in mind if using siunitx. First, it requires e-TeX, which can be an issue with some publishers (even over 10 years after it was finalised!). Secondly, the formatting does take up some time. There are settings to turn things off but it’s always the case that working by hand will ultimately be faster. However, the upside of clearer and more flexible input is in my opinion worth it.
使用 siunitx 时需注意两点:首先,它依赖 e-TeX,这可能对部分出版商造成限制(即使在 e-TeX 定稿十多年后依然如此);其次,格式化过程会占用一定时间,尽管可通过设置关闭部分功能,但手动排版终究更快。不过,在我看来,更清晰、更灵活的输入方式所带来的优势是值得的。

One other point is that siunitx is under development, with bug fixes and new features (there is a list for v3.1). In contrast, both SIunits and SIstyle are depreciated: bug fixes only. The units and unitsdef packages have not been updated for many years.
另一点需要说明的是,siunitx 仍在持续开发中,包含错误修复和新功能(v3.1 版本有相关功能列表)。相比之下,SIunitsSIstyle 已被废弃,仅提供错误修复;而 unitsunitsdef 宏包已多年未更新。

edited Jun 24, 2021 at 10:39
answered Aug 24, 2010 at 13:36
Joseph Wright♦

Great answer! I gotta look at the code sample later, with more time. You forgot to cite cjwunits and hepunits.
很棒的回答!我之后会抽时间仔细看看代码示例。你忘记提到 cjwunitshepunits 了哦。
– Denilson Sá Maia
Commented Aug 24, 2010 at 20:26

hepunits is an extension of SIunits. I’m not familiar with cjwunits, but a quick read through the code suggests is a simple approach to providing something like unitsdef-style units.
hepunitsSIunits 的扩展包。我对 cjwunits 不太熟悉,但快速浏览其代码后发现,它采用简单的方式提供了类似 unitsdef 风格的单位功能。
– Joseph Wright ♦
Commented Aug 24, 2010 at 20:43

Does siunitx have any conflict inside align* environment? I get ! Package siunitx Error: Invalid token '\protect ' in numerical input.
siunitxalign* 环境中是否存在冲突?我遇到了错误:! Package siunitx Error: Invalid token '\protect ' in numerical input.
– Kedar Mhaswade
Commented Nov 5, 2020 at 0:40

Is this advice still current (2021)? In particular, the code example seems different from what is supported by current siunitx. I’ve always used unitsdef and I was going to update to siunitx since it’s actively maintained, but the two packages are incompatible, so this prevents a smooth transition, forcing me to change every unitsdef usage in a document at once, which could be a bit disruptive.
这些建议在 2021 年仍然适用吗?特别是代码示例似乎与当前 siunitx 支持的语法不同。我一直使用 unitsdef,由于 siunitx 仍在积极维护,我打算升级到该宏包,但这两个宏包不兼容,导致无法平滑过渡,必须一次性修改文档中所有 unitsdef 的用法,这可能会带来一定的麻烦。
– LorenzoDonati4Ukraine-OnStrike
Commented Dec 21, 2021 at 15:12

@LorenzoDonati–Codidact.com The code example was updated recently to match the v3 change. As you say, siunitx is incompatible with unitsdef: that’s a consequence of using the same document command names.
@LorenzoDonati–Codidact.com 代码示例最近已更新,以适配 v3 版本的变化。如你所说,siunitxunitsdef 不兼容:这是由于两者使用了相同的文档命令名称所致。
– Joseph Wright ♦
Commented Dec 21, 2021 at 18:57


Why use a package to typeset units?

为什么需要使用宏包来排版单位?

I’ve seen a lot of posts about different packages for typesetting units and their relative strengths and weaknesses. Most posts seem to agree that the siunitx package is the most up to date package, but I haven’t really figured out the advantages of using a package at all. What is the advantage of writing something like:
我看过很多关于不同单位排版宏包及其优缺点的帖子。大多数帖子似乎都认为 siunitx 是最新的宏包,但我始终没有弄明白使用宏包的根本优势。例如,使用以下写法的优势是什么:

\SI{10}{\kilo\gram\meter\per\second\squared}

when you could just write:
而不是直接写成:

kg m s$^-2$

Or for numbers, what’s the difference between
或者对于数值,以下两种写法有什么区别:

\num{10}

and

10

edited Apr 9, 2013 at 23:33
doncherry
asked Apr 9, 2013 at 23:24
Vyas

You can write \SI{10}{kg m s^{-2}}, which guarantees that the unit will be typeset in the correct way: the right space (or multiplication symbol if you so decide) between the various parts, no line break between them, the right glyph shape (upright even if the context is italics) and so on.
你可以写成 \SI{10}{kg m s^{-2}},这能确保单位以正确的方式排版:各部分之间的间距恰当(或根据设置使用乘号)、不允许换行、字形正确(即使在斜体上下文下仍保持直立)等。
– egreg
Commented Apr 9, 2013 at 23:30

@egreg You should write \SI{10}{\kg\m\per\square\s} instead of \SI{10}{kg m s^{-2}} to get the correct spacing and a consistent output.
@egreg 为了获得正确的间距和一致的输出,你应该写成 \SI{10}{\kg\m\per\square\s},而不是 \SI{10}{kg m s^{-2}}
– Svend Tveskæg
Commented Apr 9, 2013 at 23:42

@SvendTveskæg I forgot the dots: \SI{10}{kg.m.s^{-2}} or, for the fraction form, \SI{10}{kg.m/s^{2}}.
@SvendTveskæg 我忘记加圆点了:\SI{10}{kg.m.s^{-2}},或者分数形式 \SI{10}{kg.m/s^{2}}
– egreg
Commented Apr 9, 2013 at 23:49

I would still say that the other way is “more” correct; check, e.g., the following: \documentclass{article} \usepackage{siunitx} \DeclareSIUnit\second{Horse} \begin{document} Should you write \SI{10}{\kg\m\per\square\s} or \SI{10}{kg.m.s^{-2}}? \end{document}. The formatting options is only avaliable with the approach I suggest.
我仍然认为另一种方式“更”正确;例如,查看以下代码:\documentclass{article} \usepackage{siunitx} \DeclareSIUnit\second{Horse} \begin{document} Should you write \SI{10}{\kg\m\per\square\s} or \SI{10}{kg.m.s^{-2}}? \end{document}。只有我建议的方式支持格式化选项。
– Svend Tveskæg
Commented Apr 9, 2013 at 23:54

Correct spacing for larger numbers is also a plus. KaTeX parse error: Undefined control sequence: \num at position 1: \̲n̲u̲m̲{10000} will output 10 000. Writing 10   000 10\,000 10000, seems very hacky to me.
大数的正确间距也是一个优势。\num{10000} 会输出 10 000,而手动写成 10\,000 在我看来非常繁琐。
– N3buchadnezzar
Commented Apr 18, 2013 at 7:40

Answers

I came to this question thinking “yeah! Why?” but upon reading the currently extant comments and answer I have already changed my tune and am now tending the other way. What I realized, thinking about it and about my small interactions with this package, is that it provides much the same service within LaTeX as LaTeX (or even just TeX itself) provides for writing as a whole. To understand that point, consider the alternatives in communicating some math in writing via a computer:
我看到这个问题时的第一反应是“对啊!为什么要这么麻烦?”,但在阅读了现有的评论和回答后,我的观点发生了转变,现在更倾向于使用宏包。通过思考以及我对该宏包的少量使用经验,我意识到它在 LaTeX 中提供的功能,与 LaTeX(甚至只是 TeX 本身)在整体写作中提供的服务非常相似。为了理解这一点,我们可以对比通过计算机书面交流数学内容的几种方式:

  1. Write it phonetically, as it were. Words are words, of course, but Greek letters are spelled out, or perhaps drawn in some ad-hoc ASCII art, and more complicated formulas are hacked together in an unspecified manner that may or may not be clear from context.
    可以说,是“语音化”书写。文字本身就是文字,但希腊字母需要拼写出来,或者用临时的 ASCII 艺术绘制,更复杂的公式则以不确定的方式拼凑而成,其含义可能需要结合上下文才能理解。

  2. Write it in TeX, in which Greek letters are spelled out in macros, more complicated formulas are hacked together in some possibly awful manner…and then the result is “compiled” into a document making it all look like you had in mind, so no harm done if your source was a little more schematic than you’d have liked.
    使用 TeX 书写,其中希腊字母通过宏命令拼写,更复杂的公式可能以某种不太理想的方式拼凑而成……但最终结果会“编译”成文档,呈现出你想要的样子,因此即使源文件比你期望的更具示意性,也不会有问题。

The siunitx package does exactly this, but instead of math formulas, it does SI-style units. Sure, one could write the same symbols that normally appear in such units as kg or s$^{-1}$, but that can go wrong visually very easily depending on if the unit appears in math mode or not (just imagine how that affects the latter!), or if several units become crammed together, or (egreg’s quite valid observation) broken across a line. Then you may decide that instead of s$^{-1}$ you really want /s for the unit of hertz, necessitating a global change of notation.
siunitx 宏包正是这样做的,但它处理的是国际单位制(SI)风格的单位,而非数学公式。当然,人们可以直接写出单位中常见的符号,如 kgs$^{-1}$,但这种方式很容易出现视觉上的问题——这取决于单位是否在数学模式下使用(试想这会对后者产生怎样的影响!),或者多个单位是否拥挤在一起,又或者(正如 egreg 所指出的合理观察)单位被换行分隔。之后,你可能会决定将赫兹的单位从 s$^{-1}$ 改为 /s,这就需要全局修改符号表示方式。

These are all the kinds of problems that are handled in TeX by defining macros containing your preferred styles for \kilogram and \hertz and so on. The siunitx just organizes the whole project of defining these macros and their relationships to each other, and gives a lot of aesthetic options on top of it.
这些问题在 TeX 中都可以通过定义宏来解决,例如为 \kilogram\hertz 等单位定义你偏好的样式。siunitx 宏包只是将定义这些宏及其相互关系的整个过程系统化,并在此基础上提供了大量的美观排版选项。

Basically, it boils down to “Why would anyone want to program their document in the first place?”, to which the answer is “It’s easier to write well-structured documents that way.”
归根结底,这相当于问“为什么有人愿意用编程的方式来撰写文档?”,而答案是“这样更容易写出结构良好的文档”。

answered Apr 9, 2013 at 23:40
Ryan Reich

Allow me to give an answer in the form of a practical anecdote:
请允许我通过一个实际的轶事来回答这个问题:

When I wrote my PhD dissertation in chemistry, each chapter had either been published in or was soon to be submitted to a peer-reviewed journal. Each chapter was written at a different time over the course of several years, and of course each journal had its own standards as to whether there should be a space between the number and the unit, whether inverse units should be given as fractions or exponents, etc. Besides that, when I would just type out the units, sometime I would add a space and sometime I wouldn’t, and so ended up doing a lot of proofreading to catch this until I hit on siunit, and then on siunitx.
当我撰写化学博士论文时,每个章节要么已经发表在同行评审期刊上,要么即将提交。这些章节是在几年间的不同时间撰写的,而每个期刊都有自己的格式标准——例如数值与单位之间是否需要空格、倒数单位应采用分数形式还是指数形式等。此外,当我直接输入单位时,有时会加空格,有时不会,这导致我需要花费大量时间校对,直到我发现了 siunit 宏包,后来又使用了 siunitx

By turning the units into macros, I had one less formatting issue that I had to worry about, and when I took the body of the chapter, I just had to write a new header using the journal’s style package and the correct siunitx parameters (or, if the journal didn’t support it, hard-code the macros in the preamble), and all the units and numbers were automagically formatted correctly. When I then needed to put them into my thesis, I just had to \input{} the body of the text after a \chapter{} tag, and all of my chapters were formatted to my university thesis standards with no fuss, no muss. Meanwhile, my friends who were working with Word were spending weeks and sometimes months doing nothing but reformatting and proofreading to get everything consistent (most of that spent on equation, figure, and reference numbering that I never gave a second thought to).
通过将单位转换为宏命令,我少了一个需要担心的格式问题。当我使用章节正文时,只需使用期刊的样式宏包和正确的 siunitx 参数编写新的页眉(如果期刊不支持该宏包,则在导言区硬编码宏命令),所有的单位和数值就会自动格式化为正确的样式。之后,当我需要将这些内容整合到论文中时,只需在 \chapter{} 命令后使用 \input{} 导入正文,所有章节就会自动按照大学的论文标准格式化,无需额外操作。与此同时,我那些使用 Word 的朋友们却要花费数周甚至数月的时间专门进行格式调整和校对,以确保所有内容的一致性(其中大部分时间用于处理公式、图表和参考文献的编号,而这些在 LaTeX 中我从未费心考虑过)。

In fact, the file that had my macro definitions ended up being almost as long as my chapters, since every time I had a mathematical symbol (superscripts, subscripts, bold, etc.), I created a macro with a descriptive name so that not only was it easier to proofread, but if for some reason I had to change a symbol or variable, I only had to change it once. Same idea with units. If everything is a macro, if you need to change something, you only have to change it once and that propagates itself throughout the document without having to worry.
事实上,我用于存储宏定义的文件最终几乎和章节正文一样长。因为每次遇到数学符号(上标、下标、粗体等),我都会创建一个具有描述性名称的宏命令,这样不仅更容易校对,而且如果由于某种原因需要修改符号或变量,只需修改一次即可。单位的处理也是如此。如果所有内容都通过宏命令定义,那么修改时只需改动一处,更改就会自动传播到整个文档,无需额外担心。

answered Apr 10, 2013 at 0:42
craigim

@doncherry Thanks. I lurked around for quite a while before I found a question I actually knew the answer to
@doncherry 谢谢。我潜伏了很久,才找到一个我确实知道答案的问题
– craigim
Commented Apr 10, 2013 at 0:53

As with all of the other components of TeX, LaTeX, and friends, the idea is to separate content from form
TeXLaTeX 及相关工具的所有其他组件一样,其核心思想是实现内容与形式的分离。

We wish to specify the changes globally in the preamble, and not worry about the details things in the document.
我们希望在导言区全局指定格式设置,而不必担心文档中的细节问题。

Similar questions:
类似的问题:

  • Why don’t we write \textbf{1. Introduction} instead of \section{Introduction}?
    为什么我们不写成 \textbf{1. Introduction},而是使用 \section{Introduction}

  • Why do we use the enumerate environment when we could just write (a), (b), (c) etc ?
    为什么我们使用 enumerate 环境,而不是直接写成 (a)(b)(c) 等?

  • Why do we choose to make our graphics in LaTeX (using tikz and pstricks for example) when we could make them externally and just include them?
    为什么我们选择在 LaTeX 中制作图形(例如使用 tikzpstricks 宏包),而不是在外部制作后再导入?

  • Why do we use biblatex (and other bibliography packages) to organize our references- couldn’t we just type them in the correct order ourselves?
    为什么我们使用 biblatex(及其他参考文献宏包)来管理参考文献,而不是手动按正确顺序输入?

edited Apr 9, 2013 at 23:45
answered Apr 9, 2013 at 23:36
cmhughes

I see your point in general, and I agree with the basic principle of separating style and content in LaTeX. I just never really considered units as something required that much formatting, although clearly there’s a lot of small details I didn’t consider such as italicization and spacing
我大致理解你的观点,也同意 LaTeX 中内容与样式分离的基本原则。我只是从未真正认为单位需要如此多的格式设置,尽管显然有很多细节我没有考虑到,例如斜体和间距问题。
– Vyas
Commented Apr 10, 2013 at 2:02

Whether in math mode or not, I will
无论是否在数学模式下,我都会:

  • always use \num from siunitx for any numerical literals,
    对所有数值常量始终使用 siunitx 宏包的 \num 命令,

  • always use . for the decimal marker in the decimal literals,
    在数值常量中始终使用 . 作为小数点分隔符,

  • but later set the global setting in the preamble to specify the decimal marker for the rendered output.
    但之后在导言区通过全局设置指定输出文档中的小数点分隔符。

\documentclass{article}

\usepackage{siunitx}
\sisetup{
%output-decimal-marker={,}% just uncomment if you want to use comma as the decimal marker!
}

\begin{document}
$\num{3.14}$ is not the value of $\pi$, \num{2.718281828} is not the value of $e$.
\end{document}

This mechanism makes your document portable!
这种机制使你的文档具有可移植性!

answered Apr 10, 2013 at 0:46
kiss my armpit

How do you feel about using \num for integer literals?
你对将 \num 用于整数常量有何看法?
– quser
Commented Jun 4, 2020 at 4:17

The advantage of using a package is that you get set the numbers and units in a consistent typographycal way. Sometimes you have to use a spatium (\,) between number and unit, sometimes not. Package siunitx knows about this and does it automatically right for you.
使用宏包的优势在于,你可以以一致的排版方式设置数值和单位。有时需要在数值和单位之间使用间距(\,),有时则不需要。siunitx 宏包了解这些规则,并会自动为你正确处理。

edited Apr 13, 2013 at 12:12
answered Apr 9, 2013 at 23:28
Mensch


via:

内容概要:本文围绕SecureCRT自动化脚本开发在毕业设计中的应用,系统介绍了如何利用SecureCRT的脚本功能(支持Python、VBScript等)提升计算机、网络工程等相关专业毕业设计的效率质量。文章从关键概念入手,阐明了SecureCRT脚本的核心对象(如crt、Screen、Session)及其在解决多设备调试、重复操作、跨场景验证等毕业设计常见痛点中的价值。通过三个典型应用场景——网络设备配置一致性验证、嵌入式系统稳定性测试、云平台CLI兼容性测试,展示了脚本的实际赋能效果,并以Python实现的交换机端口安全配置验证脚本为例,深入解析了会话管理、屏幕同步、输出解析、异常处理和结果导出等关键技术细节。最后展望了低代码化、AI辅助调试和云边协同等未来发展趋势。; 适合人群:计算机、网络工程、物联网、云计算等相关专业,具备一定编程基础(尤其是Python)的本科或研究生毕业生,以及需要进行设备自动化操作的科研人员; 使用场景及目标:①实现批量网络设备配置的自动验证报告生成;②长时间自动化采集嵌入式系统串口数据;③批量执行云平台CLI命令并分析兼容性差异;目标是提升毕业设计的操作效率、增强实验可复现性数据严谨性; 阅读建议:建议读者结合自身毕业设计课题,参考文中代码案例进行本地实践,重点关注异常处理机制正则表达式的适配,并注意敏感信息(如密码)的加密管理,同时可探索将脚本外部工具(如Excel、数据库)集成以增强结果分析能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值