The Python Tutorial 3.2 - 8Errors and Exceptions(错误和异常)

数据库执行查询计划详细代码分析 查询调用的函数栈: main()->PostmasterMain()->ServerLoop()->BackendStartup()->BackendRun()->PostgresMain()->exec_simple_query()→ 其中的postgresmain函数的分析进入下: //postgres主循环--所有后端,交互或者其他从这里开始 //postgres服务进程 void PostgresMain(int argc, char *argv[],... 阅读详情

8. Errors and Exceptions错误和异常


Until now error messages haven’t been more than mentioned, but if you have tried out the examples you have probably seen some. There are (at least) two distinguishable kinds of errors: syntax errors and exceptions.

直到现在,我们仍未提及错误信息,但如果你试验过示例,你大概已经看过一些。这里有(至少)两种不同类型的错误:语法错误和异常。

8.1. Syntax Errors语法错误

Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are still learning Python:

语法错误,也称作解析错误,也许是你学习Python过程中最常见抱怨。

>>> while True print('Hello world')
  File "", line 1, in ?
    while True print('Hello world')
                   ^
SyntaxError: invalid syntax

The parser repeats the offending line and displays a little ‘arrow’ pointing at the earliest point in the line where the error was detected. The error is caused by (or at least detected at) the token preceding the arrow: in the example, the error is detected at the function print(), since a colon (':') is missing before it. File name and line number are printed so you know where to look in case the input came from a script.

语法分析器重复输出错误行,并且在错误被检测到的最初位置前面显示一个小“箭头”。错误是由箭头前面标记引起的(或者至少是检测所在):这个例子中,函数 print() 被发现存在错误,因为它前面少了一个冒号( ':' )。如果是从脚本输入,错误会输出文件名和行号,所以你就知道去哪里检查错误了。

8.2. Exceptions异常

Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called exceptions and are not unconditionally fatal: you will soon learn how to handle them in Python programs. Most exceptions are not handled by programs, however, and result in error messages as shown here:

即使一条语句或表达式在语法上是正确的,当试图执行它时也可能会引发错误。运行期检测到的错误称为异常,并且程序不会无条件崩溃:很快你将学到如何在Python程序中处理它们。大多数异常都不会被程序处理,然而,像这样会引起像如图所示的错误信息:

>>> 10 * (1/0)
Traceback (most recent call last):
  File "", line 1, in ?
ZeroDivisionError: int division or modulo by zero
>>> 4 + spam*3
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'spam' is not defined
>>> '2' + 2
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: Can't convert 'int' object to str implicitly

The last line of the error message indicates what happened. Exceptions come in different types, and the type is printed as part of the message: the types in the example are ZeroDivisionError, NameError and TypeError. The string printed as the exception type is the name of the built-in exception that occurred. This is true for all built-in exceptions, but need not be true for user-defined exceptions (although it is a useful convention). Standard exception names are built-in identifiers (not reserved keywords).

错误信息最后一行指明发生了什么。异常是以不同的类型出现的,并且类型也被当做信息的一部分打印出来:示例中包含 ZeroDivisionError , NameError 和 TypeError 类型。异常发生时打印的异常类型字符串就是内置异常的名称。这适合于内置异常,但不一定适合于自定义异常(尽管这是一个有用的规范)。标准异常的名称都是内置标识符(非保留关键字)。

The rest of the line provides detail based on the type of exception and what caused it.

这行剩余部分提供了基于异常类型和引发异常相关的详细信息。

The preceding part of the error message shows the context where the exception happened, in the form of a stack traceback. In general it contains a stack traceback listing source lines; however, it will not display lines read from standard input.

异常信息的前面部分以堆栈回溯的形式显示了异常发生的上下文。通常,它包含一个堆栈回溯的源代码行的清单,但从标准输入读取的行不会被显示。

Built-in Exceptions lists the built-in exceptions and their meanings.

内置exception文档列出了内置异常及其用途。

8.3. Handling Exceptions异常处理

It is possible to write programs that handle selected exceptions. Look at the following example, which asks the user for input until a valid integer has been entered, but allows the user to interrupt the program (using Control-C or whatever the operating system supports); note that a user-generated interruption is signalled by raising the KeyboardInterrupt exception.

通过编程处理选择的异常是可行的。看下面的例,它会一直要求用户输入,直到输入一个合法的整数为止,但允许用户中断这个程序(使用 Control-C 或系统支持的任何方法)。注意:用户产生的中断会引发一个 KeyboardInterrupt 异常。

>>> while True:
...     try:
...         x = int(input("Please enter a number: "))
...         break
...     except ValueError:
...         print("Oops!  That was no valid number.  Try again...")
...

The try statement works as follows.

try语句按如下方式工作:

  • First, the try clause (the statement(s) between the try and except keywords) is executed.
  • 首先,执行try子句(在try与except关键字之间的语句)
  • If no exception occurs, the except clause is skipped and execution of the try statement is finished.
  • 如果没有异常发生,except子句就会被跳过,try语句执行完毕
  • If an exception occurs during execution of the try clause, the rest of the clause is skipped. Then if its type matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement.
  • 如果在执行try子句时发生异常,子句的剩余部分被跳过。如果异常的类型与 except 后面的异常名称相匹配,那么 except 子句就会被执行,然后继续执行 try 语句之后的代码。
  • If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements; if no handler is found, it is an unhandled exception and execution stops with a message as shown above.
  • 如果一个异常没有任何 except 子句中的异常名称与之匹配,那么它就会被传递try 语句外层 ;如果仍然没有找到处理这个异常的语句,它就成了一个未处理的异常并且中止代码执行,像上面那样显示一条信息。

A try statement may have more than one except clause, to specify handlers for different exceptions. At most one handler will be executed. Handlers only handle exceptions that occur in the corresponding try clause, not in other handlers of the same try statement. An except clause may name multiple exceptions as a parenthesized tuple, for example:

一个 try 语句可以有多个 except 子句,用来明确的处理不同的异常。最多只有一个异常处理子句会被执行。异常处理子句只处理对应的 try 子句中发生的异常,而不是其他的 try 语句发生的异常。一个 except 子句可以通过带括号的元组(tuple)定义多个异常类型,例如:

... except (RuntimeError, TypeError, NameError):
...     pass

The last except clause may omit the exception name(s), to serve as a wildcard. Use this with extreme caution, since it is easy to mask a real programming error in this way! It can also be used to print an error message and then re-raise the exception (allowing a caller to handle the exception as well):

最后一个 except 子句可以省略异常名称,以作为通配符使用。你需要慎用此法,因为它会轻易隐藏一个实际的程序错误!可以使用这种方法打印一条错误信息,然后重新抛出异常(允许调用者处理这个异常)。

import sys

try:
    f = open('myfile.txt')
    s = f.readline()
    i = int(s.strip())
except IOError as err:
    print("I/O error: {0}".format(err))
except ValueError:
    print("Could not convert data to an integer.")
except:
    print("Unexpected error:", sys.exc_info()[0])
    raise

The try ... except statement has an optional else clause, which, when present, must follow all except clauses. It is useful for code that must be executed if the try clause does not raise an exception. For example:

try...except语句有一个可选的else子句,如果存此子句,它必须在所在except子句之后。这对那些如果 try 子句没有抛出异常必须执行的代码就非常有用。

for arg in sys.argv[1:]:
    try:
        f = open(arg, 'r')
    except IOError:
        print('cannot open', arg)
    else:
        print(arg, 'has', len(f.readlines()), 'lines')
        f.close()

The use of the else clause is better than adding additional code to the try clause because it avoids accidentally catching an exception that wasn’t raised by the code being protected by the try ... except statement.

使用 else 子句比向 try 子句添加额外的代码更好,因为它避免了意外捕获的异常,它们并不是由 try...except 语句保护的代码所抛出。

When an exception occurs, it may have an associated value, also known as the exception’s argument. The presence and type of the argument depend on the exception type.

当一个异常发生时,它可能含有一个相关值,又称为异常参数。是否存在此参数及其类型取决于异常的类型。

The except clause may specify a variable after the exception name. The variable is bound to an exception instance with the arguments stored in instance.args. For convenience, the exception instance defines __str__() so the arguments can be printed directly without having to reference .args. One may also instantiate an exception first before raising it and add any attributes to it as desired.

except 子句可以在异常名称后面指定一个变量。这个变量以存储在 instance.args 中的参数形式绑定到一个异常实例。方便起见,异常实例定义了 __str__() 方法,所以这个参数可以被直接打印出来而无需通过 .args 引用。你也可以在抛出异常前先实例化它,然后给它添加任何想要的属性。

>>> try:
...    raise Exception('spam', 'eggs')
... except Exception as inst:
...    print(type(inst))    # the exception instance
...    print(inst.args)     # arguments stored in .args
...    print(inst)          # __str__ allows args to be printed directly,
...                         # but may be overridden in exception subclasses
...    x, y = inst.args     # unpack args
...    print('x =', x)
...    print('y =', y)
...

('spam', 'eggs')
('spam', 'eggs')
x = spam
y = eggs

If an exception has arguments, they are printed as the last part (‘detail’) of the message for unhandled exceptions.

对于那些未处理的异常,如果一个它们带有参数,那么就会被作为异常信息的最后部分(“详情”)打印出来。

Exception handlers don’t just handle exceptions if they occur immediately in the try clause, but also if they occur inside functions that are called (even indirectly) in the try clause. For example:

异常处理器不仅仅处理那些在 try 子句中立刻发生的异常,也会处理那些 try 子句中调用的函数内部发生的异常。例如:

>>> def this_fails():
...     x = 1/0
...
>>> try:
...     this_fails()
... except ZeroDivisionError as err:
...     print('Handling run-time error:', err)
...
Handling run-time error: int division or modulo by zero

8.4. Raising Exceptions抛出异常

The raise statement allows the programmer to force a specified exception to occur. For example:

raise 语句允许程序员强制抛出一个指定的异常。例如:

>>> raise NameError('HiThere')
Traceback (most recent call last):
  File "", line 1, in ?
NameError: HiThere

The sole argument to raise indicates the exception to be raised. This must be either an exception instance or an exception class (a class that derives from Exception).

raise 唯一的参数指定了要抛出的异常。它必须是一个异常实例,或者是异常类(继承自 Exception 的类)。

If you need to determine whether an exception was raised but don’t intend to handle it, a simpler form of the raise statement allows you to re-raise the exception:

如果你需要确定是否抛出了一个异常而并不想去处理它,一个更简单方式就是 raise 语句,允许你重新抛出异常。

>>> try:
...     raise NameError('HiThere')
... except NameError:
...     print('An exception flew by!')
...     raise
...
An exception flew by!
Traceback (most recent call last):
  File "", line 2, in ?
NameError: HiThere

8.5. User-defined Exceptions自定义异常

Programs may name their own exceptions by creating a new exception class (see Classes for more about Python classes). Exceptions should typically be derived from the Exception class, either directly or indirectly. For example:

通过创建一个新的异常类,程序可以命名它们自己的异常。异常往往应该是通过直接或间接的方式继承自 Exception 类。例如:

>>> class MyError(Exception):
...     def __init__(self, value):
...         self.value = value
...     def __str__(self):
...         return repr(self.value)
...
>>> try:
...     raise MyError(2*2)
... except MyError as e:
...     print('My exception occurred, value:', e.value)
...
My exception occurred, value: 4
>>> raise MyError('oops!')
Traceback (most recent call last):
  File "", line 1, in ?
__main__.MyError: 'oops!'

In this example, the default __init__() of Exception has been overridden. The new behavior simply creates the value attribute. This replaces the default behavior of creating the args attribute.

在这个列子中, Exception 的默认方法 __init__() 被覆盖。新的行为只是简单的创建 value 属性。这替换了创建 args 属性的默认行为。

Exception classes can be defined which do anything any other class can do, but are usually kept simple, often only offering a number of attributes that allow information about the error to be extracted by handlers for the exception. When creating a module that can raise several distinct errors, a common practice is to create a base class for exceptions defined by that module, and subclass that to create specific exception classes for different error conditions:

异常类可以定义成像其他类一样做任何事情,但一般都会保持简洁,通常只提供一些属性以便于异常处理器获取错误相关信息。当创建一个可以产生几种不同错误的模块时,一种通常的做法是为模块中定义的异常创建一个基础类,然后为不同的错误情况创建特定的子异常类。

class Error(Exception):
    """Base class for exceptions in this module."""
    pass

class InputError(Error):
    """Exception raised for errors in the input.

    Attributes:
        expression -- input expression in which the error occurred
        message -- explanation of the error
    """

    def __init__(self, expression, message):
        self.expression = expression
        self.message = message

class TransitionError(Error):
    """Raised when an operation attempts a state transition that's not
    allowed.

    Attributes:
        previous -- state at beginning of transition
        next -- attempted new state
        message -- explanation of why the specific transition is not allowed
    """

    def __init__(self, previous, next, message):
        self.previous = previous
        self.next = next
        self.message = message

Most exceptions are defined with names that end in “Error,” similar to the naming of the standard exceptions.

大多数异常的名字都是以“Error”结尾,类似标准异常命名。

Many standard modules define their own exceptions to report errors that may occur in functions they define. More information on classes is presented in chapter Classes.

许多标准模块定义它们自己的异常来报告那些可能发生在函数中错误。更多关于类的信息请参考 Classes 类 章节。

8.6. Defining Clean-up Actions定义清理动作

The try statement has another optional clause which is intended to define clean-up actions that must be executed under all circumstances. For example:

try 语句有另外一个可选的子句,可以用来定义那些在任何情况下必须执行的清理动作。例如:

>>> try:
...     raise KeyboardInterrupt
... finally:
...     print('Goodbye, world!')
...
Goodbye, world!
KeyboardInterrupt

A finally clause is always executed before leaving the try statement, whether an exception has occurred or not. When an exception has occurred in the try clause pand has not been handled by an except clause (or it has occurred in a except or else clause), it is re-raised after the finally clause has been executed. The finally clause is also executed “on the way out” when any other clause of the try statement is left via a break, continue or return statement. A more complicated example:

无论是否发生异常,一个 finally 子句在离开 try 语句前总是会被执行。当在 try 子句中发生一个异常并且没有被 except 字句处理时(或者发生在 except 或 else 子句中),它将会在 finally 子句执行完后被重新抛出。即使通过 break , continue 或者 return 等其他任何子句,当要离开try语句时 finally 子句也会被执行。一个稍微复杂的列子:

>>> def divide(x, y):
...     try:
...         result = x / y
...     except ZeroDivisionError:
...         print("division by zero!")
...     else:
...         print("result is", result)
...     finally:
...         print("executing finally clause")
...
>>> divide(2, 1)
result is 2.0
executing finally clause
>>> divide(2, 0)
division by zero!
executing finally clause
>>> divide("2", "1")
executing finally clause
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 3, in divide
TypeError: unsupported operand type(s) for /: 'str' and 'str'

As you can see, the finally clause is executed in any event. The TypeError raised by dividing two strings is not handled by the except clause and therefore re-raised after the finally clause has been executed.

如你所见,在任何事件下 finally 子句都会执行。通过将两个字符串相除引发的 TypeError 异常并没有被 except 字句处理,因此在 finally 子句执行后被重新抛出。

In real world applications, the finally clause is useful for releasing external resources (such as files or network connections), regardless of whether the use of the resource was successful.

在真实的应用程式中,使用 finally 子句释放额外的资源(像文件或网络连接)是有用的选择,不论对资源的操作是否成功。

8.7. Predefined Clean-up Actions预定义清理动作

Some objects define standard clean-up actions to be undertaken when the object is no longer needed, regardless of whether or not the operation using the object succeeded or failed. Look at the following example, which tries to open a file and print its contents to the screen.

一些对象定义了标准的清理动作,无论使用对象的操作是否成功,当对象不再需要时它们就在后台被调用执行。下面的例子尝试打开一个文件并将其内容打印在屏幕上。

for line in open("myfile.txt"):
    print(line)

The problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing. This is not an issue in simple scripts, but can be a problem for larger applications. The with statement allows objects like files to be used in a way that ensures they are always cleaned up promptly and correctly.

这段代码的问题是当代码执行完毕后不知会过多久它才会关闭文件。这在简单的脚本中还不构成额外难题,但在大的应用程式中问题就严重了。 with 语句保证像文件这样的对象在使用完之后总是可以被立即正确的清理。

with open("myfile.txt") as f:
    for line in f:
        print(line)

After the statement is executed, the file f is always closed, even if a problem was encountered while processing the lines. Objects which, like files, provide predefined clean-up actions will indicate this in their documentation.

在这段语句执行后,文件 f 总是被关闭,甚至在处理文件行时遇到了问题。诸如文件之类的对象在它们的文档中会指出是否提供了预定义清理动作。

2021年Python开发者避坑指南:Real Python、TDD与官方文档三角支撑体系 Python是一门语法简洁但生态快速演进的通用编程语言,其核心价值在于工程落地能力而非单纯语法掌握。理解Python解释器机制、包管理(pip/venv/poetry)与异步IO(asyncio)原理,是构建稳定服务的基础;而真实项目中高频出现的ImportError、Unicode编码异常、CI环境不一致等问题,本质源于版本兼容性缺失与文档使用偏差。技术价值体现在通过最小闭环实践(如TDD驱动开发)、权威事实源验证(官方Library Reference)和生产就绪教程(Real Python)形成三角支 阅读详情

相关推荐

CTF竞赛必备:Python自动化脚本编写与核心库实战指南

在网络安全和CTF竞赛中,自动化脚本是提升效率的关键技术。其核心原理在于通过编程语言实现重复性任务的自动执行、数据处理和协议交互,从而将安全研究人员从繁琐的手动操作中解放出来,专注于漏洞逻辑分析。这项技术的价值在于大幅缩短解题时间,增强复杂攻击链的构建能力,并支持快速原型验证。在CTF应用场景中,自动化脚本广泛用于密码学暴力破解、Web目录遍历、二进制漏洞利用交互以及网络流量分析等任务。本文聚焦于Python在CTF中的实战应用,详细讲解如何利用requests库进行Web请求自动化,以及使用pwntool

weixin_34163553的博客 420

Greenplum csvlog(日志数据)检索、释义(gp_toolkit.gp_log*) ...

标签 PostgreSQL , Greenplum , csvlog , gp_toolkit 背景 由于GP为分布式数据库,当查看它的一些日志时,如果到服务器上查看,会非常的繁琐,而且不好排查问题。 例如这是某个节点的日志 2018-08-23 15:34:30.004070 CST,"digoal","postgres",p12775,th-17...

weixin_34132768的博客 833

Hermes Agent实战指南:轻量级智能体工作流框架部署与调优

智能体(Agent)是实现LLM工程化落地的核心范式,其本质是将大语言模型与工具调用、记忆管理、任务编排能力系统集成,以完成端到端目标。Hermes Agent并非微调模型,而是一套基于Python 3.10+、面向生产环境的轻量级智能体运行时框架,强调确定性执行、可观测性与低硬件门槛。它通过标准化Tool Contract、Memory Contract和Orchestrator Contract,显著降低调试复杂度与失败率,适用于自动化报表生成、跨系统数据协同、条件驱动运维等任务闭环场景。本文聚焦Her

weixin_34348174的博客 456

GP日志打印函数中关于SQL的部份

Greenplum版本为6.17 正常SQL打印 在postgres.c中正常执行完SQL后会打印SQL信息(根据log_statement的设置区分是否打印),执行打印的步骤位于exec_simple_query函数中的1645行,信息如下: /* Log immediately if dictated by log_statement */ if (check_log_statement(parsetree_list)) { ereport(LOG, (errmsg("s

weixin_42788640的博客 619

Requesty:面向生产环境的LLM统一网关与自动故障转移架构

LLM网关是现代AI应用架构中实现模型解耦、服务高可用与流量智能调度的核心中间件。其本质是通过协议抽象层屏蔽OpenAI、Anthropic、Ollama等异构模型API的语义差异,基于实时健康分(error_rate、p95 latency、uptime)动态加权路由,并在限流、超时、5xx等异常场景下触发无感降级。技术价值在于将不可控的模型服务波动转化为可度量、可编排、可观测的标准化流程,显著降低业务侧容错开发成本。典型应用场景包括智能知识库、多模态客服中台、自动化报告生成等需对接多模型厂商的企业级系统

weixin_33937778的博客 423

Qt (高仿Visio)流程图组件开发(一) 效果展示及基本开发框架构思

最近因为工作原因需要使用Qt开发一个类似于Visio的流程图组件,需满足基本的流程图功能,图元类型可自定义扩展,不同图元存有各类自定义数据,可以保存为xml文件,可以读取xml文件生成流程图等等。

qq_43793182的博客 1万+

The Python Tutorial 8——Errors and Exceptions

两类错误:语法或者是逻辑  syntax errors and exceptions. 8.1. Syntax Errors >>> while True print 'Hello world' File "", line 1, in ? while True print 'Hello world' ^ SyntaxError: inv

yangcs2009的专栏 740

高分系列卫星轨道、传感器参数等信息

遥感卫星数据简介-高分系列

中遥科 3309

笔记-python-tutorial-8.errors and exceptions

笔记-python-tutorial-8.errors and exceptions 1. errors and exceptions 1.1. syntax errors >>> while True print('Hello world') File "<stdin>", line 1 while T...

akuibpt23191的博客 178

使用Python开发TreeATE的测试脚本常见问题

ImportError: No module named py_compile 找不到 DevLangPython3.dll 以上2个问题都是没有安装正确的Python,当前TreeATE依赖32位Python 2.7版本,暂时不支持Python 3以上版本

蓝白云的专栏 1033

Windows报无法成功完成操作,因为文件包含病毒或潜在的垃圾软件的解决方法

Windows报无法成功完成操作,因为文件包含病毒或潜在的垃圾软件的解决方法 在Windows的搜索框中输入Windows安全中心,搜索到后将其打开 点击病毒和威胁防护将鼠标移动到Microsoft Defender防病毒选项处,将定期扫描打开 下滑找到管理设置 先关闭篡改防护,再点击添加或删除排除项 先点击添加排除项,再点击文件,选择报出异常的文件,将其添加到排除项中,过程中会存在跳框确认,皆点击确定,完成后就可以运行报无法成功完成操作,因为文件包含病毒或潜在的垃圾软件异常的文件

123 2万+

Python » Documentation » The Python Tutorial »8 Errors and Exceptions

8. Errors and Exceptions Until now error messages haven’t been more than mentioned, but if you have tried out the examples you have probably seen some. There are (at least) two distinguishable kinds ...

weixin_42619413的博客 442

上下双相机定位贴合(原理到应用,halcon源码详解)

上下双相机定位贴合(原理到应用,halcon源码详解) 一、简介(类型与之前的文章)看你们理解那个文章快 主要讲解上下双相机定位贴合的原理和实现过程,包括各种标定、组合使用及具体的halcon源码实现,适用于的X、Y、Z三轴加一旋转轴系统,如模组组成的多轴系统、Scara四轴机器、六轴机器人(在运行过程中保证几个自由度不动,运行即可) 二、标定介绍 这一小节总结了通用的相机和轴的相对位置模型,并对其标定进行详细讲解 本系统仅使用了九点标定,精度可做到0.05mm 九点标定作用: A、本质就是仿射变换,一个坐

苏州程序大白的博客 9974

Python3 tutorial day4

Errors and Exceptions Syntax Errors Exceptions Handling Exceptions while True: ... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ...

weixin_30325971的博客 97

ardupilot SBUS输入捕获

本节主要记录ardupilot 的sbus 输入捕获功能。ardupilot 默认支持多种无线协议控制输入设备,比如常用的PPM,SBUS,IBUS,DSM,SUMD,SRXL等协议,本节主要讲解ardupilot 如何通过定时器的pwm输入捕获来获取sbus数据。

陌城烟雨 270

菱Q系列串行通信模块QJ71C24N:概述与特点

该模块支持多种串行通信协议,包括RS-232、RS-422和RS-485等,并提供了可靠的数据传输和高效的通信性能。菱Q系列串行通信模块QJ71C24N是一款功能强大的模块,具有多种通信协议支持、高速数据传输、多点通信能力和简化配置与使用等特点。简化配置和使用:QJ71C24N模块具有简单易用的配置工具和用户界面,使得用户能够快速进行模块的设置和调整。高速数据传输:QJ71C24N模块提供了高速的数据传输能力,可实现快速的数据交换和通信。本文将介绍QJ71C24N模块的概述和特点,并提供相应的源代码示例。

IunScala的博客 1931

Python基础 - IndexError 索引超出范围的异常

IndexError是Python内置的一个异常类,继承自LookupError,而LookupError又继承自Exception。当我们在尝试通过索引访问序列中的元素时,如果提供的索引超出了该序列的有效范围,Python就会抛出IndexError异常。

千淘万漉虽辛苦,吹尽狂沙始到金 2万+

实战案例—encrypt靶场(AES固定key篇)

AES是一种对称密钥加密方法,意味着加密和解密时使用相同的密钥。AES加密存在三种形式:AES-128、AES-192和AES-256,它们分别对应于三种不同的密钥长度——128位(即16字节)、192位(即24字节)和256位(即32字节)。通常情况下,密钥的长度越长,提供的安全性就越高,但相应地,加解密过程所需的时间也会增加。默认情况下,采用的是AES-128,其提供的安全性对于大多数应用来说已经足够充分。

zhouzhou_98的博客 498

Python 异步协程:asyncio、async/await、aiohttp

Windows GUI 主线程消息循环是典型。

freeking101的博客 4390

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

FastAPI从入门到实践:构建高性能Python Web API

在现代Web开发中,API框架的选择直接影响着开发效率和系统性能。Python作为主流编程语言,其类型提示(Type Hints)机制为构建健壮的Web服务提供了坚实基础。FastAPI基于Starlette和Pydantic构建,通过深度集成Python类型系统实现了自动数据验证和API文档生成。这一设计原理不仅确保了代码的类型安全,还显著提升了开发效率。在技术价值层面,FastAPI支持原生异步编程,能够高效处理高并发请求,性能表现可与Node.js和Go相媲美。其应用场景广泛覆盖从快速原型开发到企业级

weixin_34151004的博客 461

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Opus 5语言模型技术演进:从4.8到新一代的实践指南与性能对比

大型语言模型(LLM)基于Transformer架构,通过自注意力机制实现上下文理解与文本生成。其核心原理是通过大规模预训练学习语言规律,具备强大的语义理解和生成能力。在技术价值层面,LLM显著提升了自然语言处理任务的效率,支持智能对话、代码生成等复杂场景。Opus 5作为新一代语言模型,在继承Transformer优势的基础上,通过架构优化和训练数据扩展,实现了性能的显著提升。相比前代Opus 4.8,Opus 5在语言风格多样性、代码生成质量和多语言理解等方面均有突破,特别在技术文档自动化和智能客服等应

weixin_30613433的博客 348

从零构建AI智能体:基于Hermes框架的任务规划与工具调用实践

在AI应用开发中,大语言模型(LLM)的集成常面临处理多步骤、长周期任务的挑战。传统提示工程和函数调用方式在复杂流程中往往显得脆弱。其核心原理在于通过结构化循环,将任务分解、工具执行与状态管理相结合,从而赋予AI自主规划与执行能力。这一技术价值在于显著提升了AI应用的可靠性与自动化水平,使其能够胜任客户工单处理、数据分析和自动化运维等实际场景。本文聚焦于Hermes Agent这一新兴智能体框架,深入探讨其如何通过清晰的职责分离和状态机设计,解决传统LLM集成的瓶颈,并指导开发者从环境搭建到生产部署的全流程

weixin_34006468的博客 558

爬虫教程( 2 ) --- scrapy 教程、可视化管理工具、反爬框架、ai 爬虫

scrapy 教程、可视化管理工具、反爬框架、ai 爬虫

freeking101的博客 5255

AI Agent技能开发实战:从零构建智能体工具集与集成指南

在人工智能应用开发领域,AI Agent(智能体)通过调用特定工具(Skills)来扩展其行动能力,实现从对话到执行任务的跨越。其核心原理在于将复杂功能封装为标准化接口,供大语言模型(LLM)理解和调用,从而完成文件处理、API集成、数据分析等具体操作。这种模式的技术价值在于解决了LLM“知行合一”的难题,极大地拓宽了AI在自动化流程、系统集成和智能助手等场景的应用边界。本文聚焦于AI Agent Skills开发的工程实践,详细阐述了如何从环境搭建、基础工具开发到复杂服务集成的完整路径,并深入探讨了Lan

weixin_30861459的博客 527
上一篇: The Python Tutorial 3.2-6Modules(模块)
下一篇: The Python Tutorial 3.2-4 More Control Flow Tools(深入控制流)
Lbeta
博客等级 码龄15年 4粉丝 1原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值