<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>吾爱品聚</title><link>http://milin.jltcw.com/</link><description>AI开发·量子计算·云原生技术 | 吾爱品聚 - IT前沿实战教程社区</description><item><title>微博重拳整治性别对立账号，35万粉丝'情感博主'被封禁</title><link>http://milin.jltcw.com/20258548.html</link><description>&lt;p style=&quot;text-align: center;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://tse4-mm.cn.bing.net/th/id/OIP-C.ARO03Kt-wwhxgwDSRrhHbgAAAA&quot;/&gt;&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  腾讯子公司实习HR谭某点开求职者简历时皱紧了眉头——一名台湾男博主将运营女性情感账号的经历作为'成功案例'提交，这个35万粉丝的微博账号伪装成女性，长期输出性别对立内容引流。谭某当即在招聘对话框痛斥其'污染社交平台环境'。三天后，求职者反手将聊天记录不打码挂上网，谭某遭开除，而该博主账号'@周阴婷'也被平台封禁。这场两败俱伤的冲突掀开了社交平台性别对立乱象的冰山一角。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  就在谭某被开除的次日，微博管理员公布最新治理进展：对@莉莉安说道、@FxxkFeminazi等账号实施永久禁言。前者因持续污名化异性群体、散布反婚极端言论被处置；后者则因长期发布侮辱攻击异性内容遭封禁。同步被处理的还有@绿茶发言大赏与@伊利达雷之怒，这些账号通过低俗调侃、恶意关联社会热点煽动对立，仅获得阶段性禁言。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  封禁名单持续更新。8月19日，@自信是一门学问因屡次发布煽动性言论且拒绝整改被永久禁言；更危险的信号来自@锦江老师的真爱粉，该账号借热点事件宣扬暴力解决性别矛盾，同样遭到永久封杀。这些账号的操作模式高度雷同：将社会事件强行嫁接性别议题，用'反婚''仇偶'等极端话术刺激用户神经。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  这不是微博首次出手。上月平台清理过万条违规内容，980余个账号被处罚，其中典型如@慧玲炖牛排灬使用侮辱性称呼攻击婚育群体，@7910885495_275则煽动'欠冻了'等暴力言论。但治理面临顽固挑战——当'切子宫'被包装成女性独立宣言，当武大图书馆事件中有人冒充当事人同学造谣，平台审核常落后于变异话术。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  性别对立已成流量密码。某MCN从业者透露，两性争议话题互动量常达普通内容三倍以上。这也催生'反串'产业链，如被封的'@周阴婷'通过男性运营女权账号，人为制造骂战。小红书同样陷入漩涡，'港铁穷富图'刻意渲染阶层对立，'老板压榨'话题诱导职场敌意。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  微博在最新公告中坦承：'后续将持续打击此类违规内容'，并升级三项措施——禁言期满账号限制热搜落地页曝光；收缩新发博文可见范围；暂停广告分成资格。但根除病灶需破立并举。当实习HR因个人情绪越界付出代价，这也警示着：情绪宣泄与理性监督的边界，始终是平台治理中最纤细的那根弦。&lt;/p&gt;</description><pubDate>Tue, 19 Aug 2025 17:11:31 +0800</pubDate></item><item><title>Python三种模块导入方式详解 - 初学者必备教程</title><link>http://milin.jltcw.com/20258547.html</link><description>
&lt;div class=&quot;container&quot;&gt;
&lt;header&gt;
&lt;h1&gt;Python三种模块导入方式详解&lt;/h1&gt;
&lt;p class=&quot;subtitle&quot;&gt;全面掌握模块导入技巧，提升Python开发效率&lt;/p&gt;
&lt;p class=&quot;intro&quot;&gt;在Python编程中，模块导入是组织代码、实现代码复用的关键机制。本教程详细讲解Python中三种主要的模块导入方式：import语句导入整个模块、from...import导入特定成员，以及import...as为模块创建别名。每种方法都有其适用场景，理解它们的区别对于编写清晰、高效的Python代码至关重要。&lt;/p&gt;
&lt;/header&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h2&gt;1. import 语句导入整个模块&lt;/h2&gt;
&lt;p&gt;这是最基本也是最常用的模块导入方式。&lt;span class=&quot;highlight&quot;&gt;import&lt;/span&gt; 语句允许你导入整个模块，然后通过模块名前缀访问其中的函数、类或变量。&lt;/p&gt;
&lt;h3&gt;基本语法&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    import module_name
                &lt;/div&gt;
&lt;h3&gt;代码示例&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    # 导入math模块&lt;br/&gt;
                    import math&lt;br/&gt;&lt;br/&gt;
                    
                    # 使用模块中的函数和常量&lt;br/&gt;
                    print(math.sqrt(25))  # 输出: 5.0&lt;br/&gt;
                    print(math.pi)       # 输出: 3.141592653589793
                &lt;/div&gt;
&lt;div class=&quot;pros-cons&quot;&gt;
&lt;h3&gt;优点：&lt;/h3&gt;
&lt;p&gt;• 明确显示函数/变量的来源，提高代码可读性&lt;/p&gt;
&lt;p&gt;• 避免命名冲突&lt;/p&gt;
&lt;p&gt;• 导入整个模块的命名空间&lt;/p&gt;
&lt;h3&gt;缺点：&lt;/h3&gt;
&lt;p&gt;• 使用时需要重复输入模块名&lt;/p&gt;
&lt;p&gt;• 代码可能显得冗长&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h2&gt;2. from...import 导入特定成员&lt;/h2&gt;
&lt;p&gt;当你只需要使用模块中的特定函数、类或变量时，可以使用 &lt;span class=&quot;highlight&quot;&gt;from...import&lt;/span&gt; 语句。这种方式允许你直接使用成员名称而不需要模块名前缀。&lt;/p&gt;
&lt;h3&gt;基本语法&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    from module_name import name1, name2, ...
                &lt;/div&gt;
&lt;h3&gt;代码示例&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    # 从datetime模块导入date类&lt;br/&gt;
                    from datetime import date&lt;br/&gt;&lt;br/&gt;
                    
                    # 直接使用date类&lt;br/&gt;
                    today = date.today()&lt;br/&gt;
                    print(today)  # 输出当前日期，例如: 2023-08-19
                &lt;/div&gt;
&lt;div class=&quot;pros-cons&quot;&gt;
&lt;h3&gt;优点：&lt;/h3&gt;
&lt;p&gt;• 简化代码，减少输入&lt;/p&gt;
&lt;p&gt;• 使代码更简洁易读&lt;/p&gt;
&lt;h3&gt;缺点：&lt;/h3&gt;
&lt;p&gt;• 可能引起命名冲突&lt;/p&gt;
&lt;p&gt;• 降低代码可读性（不清楚函数/变量来源）&lt;/p&gt;
&lt;/div&gt;
&lt;h3&gt;导入所有成员（慎用）&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    from module_name import *  # 不推荐
                &lt;/div&gt;
&lt;p&gt;这种方式会导入模块中所有公共名称，容易导致命名冲突和代码可读性问题，应尽量避免在生产代码中使用。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h2&gt;3. import...as 创建模块别名&lt;/h2&gt;
&lt;p&gt;当模块名称较长或容易冲突时，可以使用 &lt;span class=&quot;highlight&quot;&gt;import...as&lt;/span&gt; 语句为模块创建简短的别名。这种方式在导入名称较长的模块或避免命名冲突时特别有用。&lt;/p&gt;
&lt;h3&gt;基本语法&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    import module_name as alias
                &lt;/div&gt;
&lt;h3&gt;代码示例&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    # 导入numpy模块并创建别名np&lt;br/&gt;
                    import numpy as np&lt;br/&gt;&lt;br/&gt;
                    
                    # 使用别名访问模块成员&lt;br/&gt;
                    array = np.array([1, 2, 3, 4, 5])&lt;br/&gt;
                    print(np.mean(array))  # 输出: 3.0
                &lt;/div&gt;
&lt;div class=&quot;pros-cons&quot;&gt;
&lt;h3&gt;优点：&lt;/h3&gt;
&lt;p&gt;• 简化长模块名的使用&lt;/p&gt;
&lt;p&gt;• 避免命名冲突&lt;/p&gt;
&lt;p&gt;• 遵循社区约定（如numpy→np, pandas→pd）&lt;/p&gt;
&lt;h3&gt;缺点：&lt;/h3&gt;
&lt;p&gt;• 需要记住别名约定&lt;/p&gt;
&lt;p&gt;• 不一致的别名会导致混乱&lt;/p&gt;
&lt;/div&gt;
&lt;h3&gt;结合使用&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    from module_name import name as alias
                &lt;/div&gt;
&lt;p&gt;你也可以为导入的特定成员创建别名：&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;
                    from sklearn.ensemble import RandomForestClassifier as RFC&lt;br/&gt;&lt;br/&gt;
                    
                    # 使用别名RFC&lt;br/&gt;
                    model = RFC(n_estimators=100)
                &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;comparison&quot;&gt;
&lt;h2 style=&quot;text-align: center; color: #1a2a6c;&quot;&gt;三种导入方式比较&lt;/h2&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;导入方式&lt;/th&gt;
&lt;th&gt;使用场景&lt;/th&gt;
&lt;th&gt;代码示例&lt;/th&gt;
&lt;th&gt;推荐指数&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;import module&lt;/td&gt;
&lt;td&gt;需要模块中多个成员时&lt;/td&gt;
&lt;td&gt;import math&lt;br/&gt;math.sqrt(25)&lt;/td&gt;
&lt;td&gt;★★★★★&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;from module import name&lt;/td&gt;
&lt;td&gt;只需少量特定成员时&lt;/td&gt;
&lt;td&gt;from datetime import date&lt;br/&gt;date.today()&lt;/td&gt;
&lt;td&gt;★★★★☆&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;import module as alias&lt;/td&gt;
&lt;td&gt;模块名长或需避免冲突时&lt;/td&gt;
&lt;td&gt;import pandas as pd&lt;br/&gt;pd.DataFrame()&lt;/td&gt;
&lt;td&gt;★★★★★&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;from module import *&lt;/td&gt;
&lt;td&gt;交互式环境快速测试&lt;/td&gt;
&lt;td&gt;from math import *&lt;br/&gt;sqrt(25)&lt;/td&gt;
&lt;td&gt;★☆☆☆☆ (不推荐)&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h2&gt;最佳实践与注意事项&lt;/h2&gt;
&lt;h3&gt;1. 导入顺序规范&lt;/h3&gt;
&lt;p&gt;遵循PEP8建议的导入顺序：&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;
                # 1. 标准库模块&lt;br/&gt;
                import os&lt;br/&gt;
                import sys&lt;br/&gt;&lt;br/&gt;
                
                # 2. 第三方库模块&lt;br/&gt;
                import numpy as np&lt;br/&gt;
                import pandas as pd&lt;br/&gt;&lt;br/&gt;
                
                # 3. 本地应用程序/库模块&lt;br/&gt;
                from mypackage import mymodule
            &lt;/div&gt;
&lt;h3&gt;2. 避免循环导入&lt;/h3&gt;
&lt;p&gt;当两个模块相互导入时会导致循环导入问题。解决方案：&lt;/p&gt;
&lt;p&gt;• 重构代码结构&lt;/p&gt;
&lt;p&gt;• 将导入语句移到函数内部&lt;/p&gt;
&lt;p&gt;• 使用import语句而非from...import&lt;/p&gt;
&lt;h3&gt;3. 性能考虑&lt;/h3&gt;
&lt;p&gt;• 模块在首次导入时会被编译并执行&lt;/p&gt;
&lt;p&gt;• 重复导入：Python会缓存已导入的模块&lt;/p&gt;
&lt;p&gt;• 将不常用的导入放在函数内部可加快启动速度&lt;/p&gt;
&lt;h3&gt;4. 使用__init__.py文件&lt;/h3&gt;
&lt;p&gt;在包目录中创建__init__.py文件（可以是空文件）来使Python将目录识别为包，从而支持相对导入：&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;
                # 在mypackage/__init__.py中&lt;br/&gt;
                from . import submodule1&lt;br/&gt;
                from . import submodule2
            &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;footer&gt;
&lt;p&gt;© 2023 Python模块导入教程 | 掌握模块导入技巧，提升Python编程效率&lt;/p&gt;
&lt;/footer&gt;
</description><pubDate>Tue, 19 Aug 2025 17:07:59 +0800</pubDate></item><item><title>Python读取YAML文件教程 - 从入门到实践 | Python数据处理指南</title><link>http://milin.jltcw.com/20258546.html</link><description>
&lt;!-- 页面头部 --&gt;
&lt;header style=&quot;text-align: center; margin-bottom: 40px; padding: 20px 0; background: linear-gradient(135deg, #1e5799, #207cca); color: white; border-radius: 8px;&quot;&gt;
&lt;h1 style=&quot;margin: 0; font-size: 2.5rem; text-shadow: 2px 2px 4px rgba(0,0,0,0.3);&quot;&gt;Python读取YAML文件教程&lt;/h1&gt;
&lt;p style=&quot;font-size: 1.2rem; max-width: 700px; margin: 15px auto;&quot;&gt;全面指南：从基础语法到高级应用，掌握Python处理YAML配置文件的技巧&lt;/p&gt;
&lt;/header&gt;
&lt;!-- 主要内容区 --&gt;
&lt;main&gt;
&lt;!-- 介绍部分 --&gt;
&lt;section style=&quot;background: white; padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 30px;&quot;&gt;
&lt;h2 style=&quot;color: #1e5799; border-bottom: 2px solid #eaeaea; padding-bottom: 10px;&quot;&gt;什么是YAML？&lt;/h2&gt;
&lt;p&gt;YAML（YAML Ain't Markup Language）是一种人类可读的数据序列化标准，广泛用于配置文件和数据交换。与JSON和XML相比，YAML具有更简洁的语法和更强的可读性。&lt;/p&gt;
&lt;div style=&quot;display: flex; gap: 20px; margin-top: 20px; flex-wrap: wrap;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 280px; background: #f0f7ff; padding: 15px; border-radius: 6px; border-left: 4px solid #4a90e2;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1e5799;&quot;&gt;YAML主要特点&lt;/h3&gt;
&lt;ul style=&quot;padding-left: 20px;&quot;&gt;
&lt;li&gt;简洁直观的语法&lt;/li&gt;
&lt;li&gt;使用缩进表示层级关系&lt;/li&gt;
&lt;li&gt;支持注释（以#开头）&lt;/li&gt;
&lt;li&gt;支持复杂数据结构&lt;/li&gt;
&lt;li&gt;跨编程语言支持&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 280px; background: #fff9e6; padding: 15px; border-radius: 6px; border-left: 4px solid #f1c40f;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1e5799;&quot;&gt;常见应用场景&lt;/h3&gt;
&lt;ul style=&quot;padding-left: 20px;&quot;&gt;
&lt;li&gt;应用程序配置文件&lt;/li&gt;
&lt;li&gt;Docker Compose配置&lt;/li&gt;
&lt;li&gt;Kubernetes资源配置&lt;/li&gt;
&lt;li&gt;API规范（OpenAPI）&lt;/li&gt;
&lt;li&gt;数据序列化与持久化&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 安装部分 --&gt;
&lt;section style=&quot;background: white; padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 30px;&quot;&gt;
&lt;h2 style=&quot;color: #1e5799; border-bottom: 2px solid #eaeaea; padding-bottom: 10px;&quot;&gt;安装PyYAML库&lt;/h2&gt;
&lt;p&gt;Python使用PyYAML库来处理YAML文件。安装方法如下：&lt;/p&gt;
&lt;div style=&quot;background: #2d2d2d; color: #f8f8f2; padding: 15px; border-radius: 6px; margin: 20px 0; font-family: 'Consolas', monospace; overflow-x: auto;&quot;&gt;
&lt;pre&gt;&lt;code&gt;# 使用pip安装PyYAML
pip install pyyaml

# 或者使用conda安装
conda install pyyaml&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p style=&quot;background: #e6f7ff; padding: 15px; border-radius: 6px; border-left: 4px solid #1890ff;&quot;&gt;
&lt;strong&gt;注意：&lt;/strong&gt; 在Python 3.6及更高版本中，PyYAML库提供了完整的YAML 1.1支持。如果你需要处理更复杂的YAML结构，可以考虑使用ruamel.yaml库。
            &lt;/p&gt;
&lt;/section&gt;
&lt;!-- 基本使用部分 --&gt;
&lt;section style=&quot;background: white; padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 30px;&quot;&gt;
&lt;h2 style=&quot;color: #1e5799; border-bottom: 2px solid #eaeaea; padding-bottom: 10px;&quot;&gt;Python读取YAML文件&lt;/h2&gt;
&lt;h3 style=&quot;color: #2c6fbb;&quot;&gt;示例YAML文件 (config.yaml)&lt;/h3&gt;
&lt;div style=&quot;background: #f8f9fa; padding: 15px; border-radius: 6px; border-left: 4px solid #ced4da; margin-bottom: 20px;&quot;&gt;
&lt;pre&gt;&lt;code&gt;# 应用配置
app:
  name: &quot;My Application&quot;
  version: 1.2.3
  production: false
  ports:
    - 8000
    - 8001
    - 8002

database:
  host: &quot;localhost&quot;
  port: 5432
  credentials:
    username: &quot;admin&quot;
    password: &quot;secret&quot;

# 功能开关
features:
  analytics: true
  caching: false
  logging:
    level: &quot;debug&quot;
    path: &quot;/var/logs&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 style=&quot;color: #2c6fbb;&quot;&gt;Python读取代码&lt;/h3&gt;
&lt;div style=&quot;background: #2d2d2d; color: #f8f8f2; padding: 15px; border-radius: 6px; margin: 20px 0; font-family: 'Consolas', monospace; overflow-x: auto;&quot;&gt;
&lt;pre&gt;&lt;code&gt;import yaml

# 读取YAML文件
with open('config.yaml', 'r') as file:
    config = yaml.safe_load(file)

# 访问配置数据
print(f&quot;应用名称: {config['app']['name']}&quot;)
print(f&quot;数据库主机: {config['database']['host']}&quot;)
print(f&quot;日志级别: {config['features']['logging']['level']}&quot;)

# 获取端口列表
ports = config['app']['ports']
print(f&quot;应用端口: {', '.join(map(str, ports))}&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 style=&quot;color: #2c6fbb;&quot;&gt;输出结果&lt;/h3&gt;
&lt;div style=&quot;background: #e8f5e9; padding: 15px; border-radius: 6px; border-left: 4px solid #4caf50;&quot;&gt;
&lt;pre&gt;&lt;code&gt;应用名称: My Application
数据库主机: localhost
日志级别: debug
应用端口: 8000, 8001, 8002&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 高级用法部分 --&gt;
&lt;section style=&quot;background: white; padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 30px;&quot;&gt;
&lt;h2 style=&quot;color: #1e5799; border-bottom: 2px solid #eaeaea; padding-bottom: 10px;&quot;&gt;高级用法与技巧&lt;/h2&gt;
&lt;div style=&quot;display: flex; gap: 20px; margin-top: 20px; flex-wrap: wrap;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 280px; background: #f9f0ff; padding: 15px; border-radius: 6px; border-left: 4px solid #8e44ad;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1e5799;&quot;&gt;处理多文档YAML&lt;/h3&gt;
&lt;p&gt;YAML文件可以包含多个文档，使用&lt;code&gt;---&lt;/code&gt;分隔：&lt;/p&gt;
&lt;pre style=&quot;background: #f0f0f0; padding: 10px; border-radius: 4px; overflow-x: auto;&quot;&gt;&lt;code&gt;# 文档1
app: &quot;First Application&quot;
---
# 文档2
app: &quot;Second Application&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;读取方法：&lt;/p&gt;
&lt;pre style=&quot;background: #2d2d2d; color: #f8f8f2; padding: 10px; border-radius: 4px; overflow-x: auto;&quot;&gt;&lt;code&gt;with open('multi_doc.yaml') as file:
    documents = list(yaml.safe_load_all(file))&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 280px; background: #e6f7ff; padding: 15px; border-radius: 6px; border-left: 4px solid #1890ff;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1e5799;&quot;&gt;写入YAML文件&lt;/h3&gt;
&lt;p&gt;将Python数据写入YAML文件：&lt;/p&gt;
&lt;pre style=&quot;background: #2d2d2d; color: #f8f8f2; padding: 10px; border-radius: 4px; overflow-x: auto;&quot;&gt;&lt;code&gt;data = {
    'app': {
        'name': 'New App',
        'version': '2.0'
    },
    'features': ['auth', 'dashboard']
}

with open('output.yaml', 'w') as file:
    yaml.dump(data, file, sort_keys=False)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;sort_keys=False&lt;/code&gt;参数保持字典键的原始顺序&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-top: 20px; background: #fff8e1; padding: 15px; border-radius: 6px; border-left: 4px solid #ffc107;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1e5799;&quot;&gt;安全注意事项&lt;/h3&gt;
&lt;p&gt;使用&lt;code&gt;yaml.safe_load()&lt;/code&gt;代替&lt;code&gt;yaml.load()&lt;/code&gt;可以防止执行任意代码，避免安全漏洞。&lt;/p&gt;
&lt;p&gt;PyYAML支持自定义构造函数，这可能带来安全风险。对于不受信任的YAML输入，请始终使用&lt;code&gt;safe_load()&lt;/code&gt;。&lt;/p&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 常见问题部分 --&gt;
&lt;section style=&quot;background: white; padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #1e5799; border-bottom: 2px solid #eaeaea; padding-bottom: 10px;&quot;&gt;常见问题与解决方案&lt;/h2&gt;
&lt;div style=&quot;margin-top: 20px;&quot;&gt;
&lt;div style=&quot;background: #f8f9fa; padding: 15px; border-radius: 6px; margin-bottom: 15px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #2c3e50;&quot;&gt;1. 缩进错误&lt;/h3&gt;
&lt;p&gt;YAML对缩进非常敏感，必须使用空格而不是制表符。确保整个文件使用一致的缩进（通常2或4个空格）。&lt;/p&gt;
&lt;/div&gt;
&lt;div style=&quot;background: #f8f9fa; padding: 15px; border-radius: 6px; margin-bottom: 15px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #2c3e50;&quot;&gt;2. 特殊字符处理&lt;/h3&gt;
&lt;p&gt;包含特殊字符的字符串应该用引号包裹：&lt;/p&gt;
&lt;pre style=&quot;background: #f0f0f0; padding: 10px; border-radius: 4px; margin: 10px 0;&quot;&gt;&lt;code&gt;message: &quot;This is a string with: colon, and &amp;amp; ampersand&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;background: #f8f9fa; padding: 15px; border-radius: 6px; margin-bottom: 15px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #2c3e50;&quot;&gt;3. 数据类型转换&lt;/h3&gt;
&lt;p&gt;YAML会自动转换数据类型：&lt;/p&gt;
&lt;ul style=&quot;padding-left: 20px;&quot;&gt;
&lt;li&gt;&lt;code&gt;true/false&lt;/code&gt; → Python &lt;code&gt;True/False&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;123&lt;/code&gt; → 整数&lt;/li&gt;
&lt;li&gt;&lt;code&gt;123.45&lt;/code&gt; → 浮点数&lt;/li&gt;
&lt;li&gt;&lt;code&gt;null&lt;/code&gt; → &lt;code&gt;None&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;background: #f8f9fa; padding: 15px; border-radius: 6px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #2c3e50;&quot;&gt;4. 大文件处理&lt;/h3&gt;
&lt;p&gt;处理大型YAML文件时，使用流式处理避免内存问题：&lt;/p&gt;
&lt;pre style=&quot;background: #2d2d2d; color: #f8f8f2; padding: 10px; border-radius: 4px; overflow-x: auto;&quot;&gt;&lt;code&gt;with open('large_file.yaml') as file:
    for data in yaml.safe_load_all(file):
        process_data(data)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/main&gt;
&lt;!-- 总结部分 --&gt;
&lt;section style=&quot;margin-top: 40px; text-align: center; padding: 30px; background: linear-gradient(135deg, #2c3e50, #4a6491); color: white; border-radius: 8px;&quot;&gt;
&lt;h2 style=&quot;margin-top: 0; font-size: 1.8rem;&quot;&gt;掌握Python处理YAML文件&lt;/h2&gt;
&lt;p style=&quot;font-size: 1.1rem; max-width: 700px; margin: 15px auto;&quot;&gt;通过本教程，你已经学习了如何使用Python读取和写入YAML文件，掌握了基本和高级技巧，并了解了常见问题的解决方案。&lt;/p&gt;
&lt;div style=&quot;margin-top: 20px;&quot;&gt;
&lt;p style=&quot;font-size: 1.2rem; font-weight: bold;&quot;&gt;下一步：&lt;/p&gt;
&lt;p&gt;尝试在自己的项目中使用YAML作为配置文件格式，或将其用于数据交换！&lt;/p&gt;
&lt;/div&gt;
&lt;/section&gt;
</description><pubDate>Tue, 19 Aug 2025 17:04:09 +0800</pubDate></item><item><title>华为突增58亿弹药库，任正非持股“被动稀释”背后暗藏什么阳谋？</title><link>http://milin.jltcw.com/20258545.html</link><description>&lt;p style=&quot;text-align: center;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://tse4-mm.cn.bing.net/th/id/OIP-C.PlwJOyeqS4rDckEuHejLJQHaEG&quot;/&gt;&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  2025年8月15日，华为投资控股有限公司完成了一笔意味深长的工商变更——注册资本从580.78亿元猛增至638.86亿元，增幅恰好锁定在10%。这一动作看似常规增资，却在细节处暗流涌动。根据国家信用信息公示系统显示，此次增资规模高达58亿元，是华为近年来幅度最大的一次资本加固。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  细心观察股权变动数据会发现一个微妙变化：华为工会委员会持股比例从99.42%升至99.48%，而任正非个人持股则从0.58%降到了0.52%。更值得注意的是，任正非实际出资额纹丝未动，维持在33519.3479万元。这意味着，创始人持股并非主动减持，而是被新增资本“稀释”的结果。这种看似被动的调整，恰恰延续了华为“力出一孔，利出一孔”的独特治理哲学——将利益向奋斗者群体倾斜。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  资本弹药储备背后，华为正在多条战线同时开火。鸿蒙生态近期捷报频传：终端设备数突破1000万生死线，余承东高调宣布“三分天下有其一”的生态野心，近百亿开发者补贴砸向市场。而9月即将召开的全联接大会，更被业内视为鸿蒙6系统与AI融合的战略亮相窗口。操作系统突围战已到关键时刻，弹药消耗量不言而喻。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  在更隐秘的半导体战场，增资动作同样意味深长。尽管华为哈勃投资今年仅新增入股超声波指纹芯片厂商芯曌科技，放缓了“广撒网”节奏，但累计超百家的半导体产业链布局早已铺开。从济南天岳的碳化硅材料，到杰华特的电源管理芯片，再到长光华芯的激光器件，一条自主可控的半导体护城河正在形成。此时追加58亿资本，恰似为“精耕细作”阶段的攻坚储备粮草。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  而华为2025年已明确每年投入10亿元重注原生开发计划，围绕鲲鹏、昇腾和鸿蒙三大技术构建根生态。在昇腾AI生态中，华为正探索存算分离等前沿技术以降低推理成本。这些长期投入如同吞金兽，需要持续资本输血。注册资本增加的背后，实则是对未来十年科技竞争的前瞻押注。&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  当科技巨头们争相收缩过冬之际，华为反向扩增资本的动作显得格外醒目。这58亿既是应对当前卡脖子技术的防弹衣，更是开启操作系统、人工智能、智能汽车等新战场的冲锋号。任正非那被稀释的0.06%股权，或许正在兑换成华为穿越寒冬的又一批弹药。&lt;/p&gt;</description><pubDate>Tue, 19 Aug 2025 16:23:12 +0800</pubDate></item><item><title>Python库安装失败？7种有效解决方案与实用技巧 | Python问题解决指南</title><link>http://milin.jltcw.com/20258544.html</link><description>
&lt;!-- 页面头部 --&gt;
&lt;header style=&quot;background: linear-gradient(135deg, #2c3e50, #1a5276); padding: 30px; border-radius: 10px; margin-bottom: 30px; color: white; text-align: center;&quot;&gt;
&lt;h1 style=&quot;margin: 0; font-size: 2.5rem;&quot;&gt;Python库安装失败？完整解决方案指南&lt;/h1&gt;
&lt;p style=&quot;font-size: 1.2rem; opacity: 0.9;&quot;&gt;解决pip安装问题的7种有效方法与实用技巧&lt;/p&gt;
&lt;/header&gt;
&lt;!-- 问题介绍 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;为什么Python库安装会失败？&lt;/h2&gt;
&lt;p&gt;Python开发者在使用pip安装库时常常会遇到各种错误，常见原因包括：&lt;/p&gt;
&lt;ul style=&quot;line-height: 1.8;&quot;&gt;
&lt;li&gt;网络连接问题或访问国外源速度慢&lt;/li&gt;
&lt;li&gt;pip版本过旧不兼容新特性&lt;/li&gt;
&lt;li&gt;缺少编译依赖（特别是需要C/C++编译的包）&lt;/li&gt;
&lt;li&gt;环境变量配置问题&lt;/li&gt;
&lt;li&gt;Python环境冲突&lt;/li&gt;
&lt;li&gt;操作系统权限限制&lt;/li&gt;
&lt;li&gt;库版本与Python版本不兼容&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;background: #e3f2fd; padding: 15px; border-left: 4px solid #2196f3;&quot;&gt;本指南将一步步教你解决这些常见问题，让你的Python开发之旅更加顺畅！&lt;/p&gt;
&lt;/section&gt;
&lt;!-- 解决方案1 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;1. 升级pip工具&lt;/h2&gt;
&lt;p&gt;过时的pip版本可能是安装失败的根源。使用以下命令升级pip：&lt;/p&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 15px; border-radius: 5px; overflow: auto; margin: 15px 0;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;python -m pip install --upgrade pip&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p style=&quot;background: #e8f5e9; padding: 15px; border-left: 4px solid #4caf50;&quot;&gt;在Windows上，如果遇到权限问题，可以尝试：&lt;br/&gt;&lt;code&gt;python -m pip install --user --upgrade pip&lt;/code&gt;&lt;/p&gt;
&lt;/section&gt;
&lt;!-- 解决方案2 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;2. 使用国内镜像源&lt;/h2&gt;
&lt;p&gt;国内用户访问PyPI官方源速度较慢，可以切换至国内镜像源：&lt;/p&gt;
&lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 15px; margin: 20px 0;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #e3f2fd; padding: 15px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1a5276;&quot;&gt;临时使用镜像源&lt;/h3&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 10px; border-radius: 5px;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #e8f5e9; padding: 15px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1b5e20;&quot;&gt;设为默认源&lt;/h3&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 10px; border-radius: 5px;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 style=&quot;color: #2c3e50;&quot;&gt;推荐国内镜像源：&lt;/h3&gt;
&lt;ul style=&quot;background: #fff8e1; padding: 15px 15px 15px 35px; border-radius: 5px; border-left: 4px solid #ffc107;&quot;&gt;
&lt;li&gt;清华大学：https://pypi.tuna.tsinghua.edu.cn/simple&lt;/li&gt;
&lt;li&gt;阿里云：https://mirrors.aliyun.com/pypi/simple/&lt;/li&gt;
&lt;li&gt;豆瓣：https://pypi.douban.com/simple/&lt;/li&gt;
&lt;li&gt;中国科学技术大学：https://pypi.mirrors.ustc.edu.cn/simple/&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;!-- 解决方案3 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;3. 安装编译依赖（Windows用户）&lt;/h2&gt;
&lt;p&gt;许多Python包需要C/C++编译器才能安装。Windows用户需安装：&lt;/p&gt;
&lt;div style=&quot;display: flex; gap: 20px; margin: 20px 0; flex-wrap: wrap;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #fbe9e7; padding: 15px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #bf360c;&quot;&gt;安装Microsoft Build Tools&lt;/h3&gt;
&lt;p&gt;访问：&lt;a href=&quot;https://visualstudio.microsoft.com/visual-cpp-build-tools/&quot; style=&quot;color: #d84315; text-decoration: none;&quot;&gt;Microsoft C++ Build Tools&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;安装时选择&quot;使用C++的桌面开发&quot;工作负载&lt;/p&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #e3f2fd; padding: 15px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1a5276;&quot;&gt;使用预编译的Windows二进制包&lt;/h3&gt;
&lt;p&gt;访问：&lt;a href=&quot;https://www.lfd.uci.edu/~gohlke/pythonlibs/&quot; style=&quot;color: #1565c0; text-decoration: none;&quot;&gt;Unofficial Windows Binaries&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;下载对应版本的.whl文件，然后使用pip安装：&lt;/p&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 10px; border-radius: 5px;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;pip install 下载的whl文件路径&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 解决方案4 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;4. 使用虚拟环境&lt;/h2&gt;
&lt;p&gt;虚拟环境可以避免包冲突和权限问题：&lt;/p&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 15px; border-radius: 5px; margin: 15px 0;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;# 创建虚拟环境
python -m venv myenv

# 激活虚拟环境
# Windows:
myenv\Scripts\activate
# Linux/macOS:
source myenv/bin/activate

# 在虚拟环境中安装包
pip install 包名

# 退出虚拟环境
deactivate&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;background: #e8f5e9; padding: 15px; border-radius: 5px; border-left: 4px solid #4caf50; margin-top: 20px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1b5e20;&quot;&gt;虚拟环境的优势：&lt;/h3&gt;
&lt;ul style=&quot;margin-bottom: 0;&quot;&gt;
&lt;li&gt;隔离项目依赖，避免版本冲突&lt;/li&gt;
&lt;li&gt;不需要管理员权限&lt;/li&gt;
&lt;li&gt;保持系统Python环境干净&lt;/li&gt;
&lt;li&gt;方便不同项目使用不同Python版本&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 解决方案5 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;5. 使用Anaconda/Miniconda&lt;/h2&gt;
&lt;p&gt;Anaconda是数据科学领域常用的Python发行版，解决了大量科学计算包的依赖问题：&lt;/p&gt;
&lt;div style=&quot;display: flex; gap: 20px; margin: 20px 0; flex-wrap: wrap;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #f3e5f5; padding: 15px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #6a1b9a;&quot;&gt;安装Anaconda&lt;/h3&gt;
&lt;p&gt;从&lt;a href=&quot;https://www.anaconda.com/products/distribution&quot; style=&quot;color: #9c27b0; text-decoration: none;&quot;&gt;官网&lt;/a&gt;下载安装包&lt;/p&gt;
&lt;p&gt;包含1500+常用科学计算包&lt;/p&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #e0f7fa; padding: 15px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #006064;&quot;&gt;使用conda安装包&lt;/h3&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 10px; border-radius: 5px;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;conda install 包名&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;conda会自动解决复杂的依赖关系&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p style=&quot;background: #fff3e0; padding: 15px; border-left: 4px solid #ff9800;&quot;&gt;对于空间有限的用户，可以使用Miniconda，它是Anaconda的精简版，只包含conda和Python。&lt;/p&gt;
&lt;/section&gt;
&lt;!-- 解决方案6 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;6. 其他实用技巧&lt;/h2&gt;
&lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 15px; margin: 20px 0;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 300px; background: #e8f5e9; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1b5e20;&quot;&gt;清除pip缓存&lt;/h3&gt;
&lt;p&gt;损坏的缓存可能导致安装失败：&lt;/p&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 10px; border-radius: 5px;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;pip cache purge&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 300px; background: #e3f2fd; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #1a5276;&quot;&gt;安装特定版本&lt;/h3&gt;
&lt;p&gt;尝试安装与Python兼容的旧版本：&lt;/p&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 10px; border-radius: 5px;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;pip install 包名==版本号&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 300px; background: #fff8e1; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;margin-top: 0; color: #ff8f00;&quot;&gt;使用--user选项&lt;/h3&gt;
&lt;p&gt;解决权限问题（不需要管理员权限）：&lt;/p&gt;
&lt;div style=&quot;background: #272822; color: #f8f8f2; padding: 10px; border-radius: 5px;&quot;&gt;
&lt;pre style=&quot;margin: 0;&quot;&gt;&lt;code&gt;pip install --user 包名&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 解决方案7 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;7. 常见错误代码与解决方法&lt;/h2&gt;
&lt;table style=&quot;width: 100%; border-collapse: collapse; margin: 20px 0;&quot;&gt;
&lt;thead&gt;
&lt;tr style=&quot;background: #2c3e50; color: white;&quot;&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;错误代码/信息&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;原因&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;解决方案&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;ERROR: Could not find a version that satisfies the requirement&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;包名称错误或版本不存在&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;检查包名拼写，尝试安装其他版本&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd; background: #f9f9f9;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;ModuleNotFoundError: No module named '...'&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;包未安装或安装到错误环境&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;确认安装环境是否正确，检查Python路径&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;PermissionError: [Errno 13] Permission denied&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;权限不足&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;使用--user选项或虚拟环境&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd; background: #f9f9f9;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;Failed building wheel for ...&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;缺少编译依赖&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;安装Microsoft Build Tools或使用预编译包&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;SSLError: HTTPSConnectionPool&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;SSL证书问题&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;使用--trusted-host选项或更换镜像源&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/section&gt;
&lt;!-- 总结 --&gt;
&lt;section style=&quot;background: linear-gradient(135deg, #1a5276, #2c3e50); padding: 30px; border-radius: 10px; color: white; text-align: center;&quot;&gt;
&lt;h2 style=&quot;margin-top: 0; font-size: 1.8rem;&quot;&gt;Python库安装问题解决总结&lt;/h2&gt;
&lt;div style=&quot;display: flex; justify-content: center; flex-wrap: wrap; gap: 15px; margin: 20px 0;&quot;&gt;
&lt;div style=&quot;background: rgba(255,255,255,0.1); padding: 15px; border-radius: 8px; width: 180px;&quot;&gt;
&lt;div style=&quot;font-size: 2rem; font-weight: bold;&quot;&gt;1&lt;/div&gt;
&lt;div&gt;升级pip&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgba(255,255,255,0.1); padding: 15px; border-radius: 8px; width: 180px;&quot;&gt;
&lt;div style=&quot;font-size: 2rem; font-weight: bold;&quot;&gt;2&lt;/div&gt;
&lt;div&gt;使用镜像源&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgba(255,255,255,0.1); padding: 15px; border-radius: 8px; width: 180px;&quot;&gt;
&lt;div style=&quot;font-size: 2rem; font-weight: bold;&quot;&gt;3&lt;/div&gt;
&lt;div&gt;安装依赖&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgba(255,255,255,0.1); padding: 15px; border-radius: 8px; width: 180px;&quot;&gt;
&lt;div style=&quot;font-size: 2rem; font-weight: bold;&quot;&gt;4&lt;/div&gt;
&lt;div&gt;虚拟环境&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p style=&quot;font-size: 1.1rem;&quot;&gt;遵循这些步骤，大多数Python库安装问题都能解决。如果仍有问题，请查阅官方文档或在开发者社区寻求帮助！&lt;/p&gt;
&lt;/section&gt;
&lt;!-- 附加资源 --&gt;
&lt;section style=&quot;background: white; border-radius: 10px; padding: 25px; margin-bottom: 25px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;附加资源与参考&lt;/h2&gt;
&lt;ul style=&quot;line-height: 1.8;&quot;&gt;
&lt;li&gt;官方pip文档：&lt;a href=&quot;https://pip.pypa.io/en/stable/&quot; style=&quot;color: #1565c0; text-decoration: none;&quot;&gt;https://pip.pypa.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Python包索引(PyPI)：&lt;a href=&quot;https://pypi.org/&quot; style=&quot;color: #1565c0; text-decoration: none;&quot;&gt;https://pypi.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Anaconda文档：&lt;a href=&quot;https://docs.anaconda.com/&quot; style=&quot;color: #1565c0; text-decoration: none;&quot;&gt;https://docs.anaconda.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;虚拟环境教程：&lt;a href=&quot;https://docs.python.org/3/tutorial/venv.html&quot; style=&quot;color: #1565c0; text-decoration: none;&quot;&gt;Python官方venv文档&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Stack Overflow Python专区：&lt;a href=&quot;https://stackoverflow.com/questions/tagged/python&quot; style=&quot;color: #1565c0; text-decoration: none;&quot;&gt;Python问题解答&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
</description><pubDate>Tue, 19 Aug 2025 16:09:41 +0800</pubDate></item><item><title>Python3提取汉字的多种方法 - 实用教程</title><link>http://milin.jltcw.com/20258543.html</link><description>
&lt;header style=&quot;text-align: center; margin-bottom: 40px; padding: 20px; background: linear-gradient(135deg, #1a2980, #26d0ce); color: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);&quot;&gt;
&lt;h1 style=&quot;font-size: 2.5rem; margin-bottom: 10px;&quot;&gt;Python3提取汉字的实用指南&lt;/h1&gt;
&lt;p style=&quot;font-size: 1.2rem; opacity: 0.9;&quot;&gt;多种方法高效提取文本中的汉字&lt;/p&gt;
&lt;/header&gt;
&lt;section style=&quot;margin-bottom: 40px; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);&quot;&gt;
&lt;h2 style=&quot;color: #1a2980; border-bottom: 2px solid #26d0ce; padding-bottom: 10px;&quot;&gt;为什么需要提取汉字？&lt;/h2&gt;
&lt;p&gt;在中文文本处理、数据清洗和分析中，经常需要从混合文本（包含汉字、字母、数字、标点等）中提取纯汉字内容：&lt;/p&gt;
&lt;ul style=&quot;list-style-type: circle; padding-left: 25px;&quot;&gt;
&lt;li&gt;中文文本分析&lt;/li&gt;
&lt;li&gt;数据清洗和预处理&lt;/li&gt;
&lt;li&gt;自然语言处理任务&lt;/li&gt;
&lt;li&gt;生成纯中文文本&lt;/li&gt;
&lt;li&gt;去除不需要的字符&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);&quot;&gt;
&lt;h2 style=&quot;color: #1a2980; border-bottom: 2px solid #26d0ce; padding-bottom: 10px;&quot;&gt;方法1：使用正则表达式&lt;/h2&gt;
&lt;p&gt;最常用且高效的方法是利用Python的&lt;code&gt;re&lt;/code&gt;模块匹配中文字符的Unicode范围。&lt;/p&gt;
&lt;div style=&quot;background: #f5f7ff; padding: 15px; border-left: 4px solid #4e73df; margin: 15px 0; border-radius: 0 8px 8px 0;&quot;&gt;
&lt;pre style=&quot;background: #2d3748; color: #e2e8f0; padding: 15px; border-radius: 6px; overflow: auto; margin: 0; font-family: 'Consolas', monospace;&quot;&gt;
import re

def extract_chinese_re(text):
    # 匹配所有中文字符（包括汉字和中文标点）
    pattern = re.compile(r'[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]')
    result = ''.join(pattern.findall(text))
    return result

# 示例用法
text = &quot;Hello, 世界! 2023年Python教程。&quot;
print(extract_chinese_re(text))  # 输出: &quot;世界年Python教程。&quot;
            &lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;display: flex; margin-top: 20px;&quot;&gt;
&lt;div style=&quot;flex: 1; padding: 15px; background: #e6f7ff; margin-right: 10px; border-radius: 6px;&quot;&gt;
&lt;h3 style=&quot;color: #0056b3;&quot;&gt;优点&lt;/h3&gt;
&lt;ul style=&quot;list-style-type: circle; padding-left: 20px;&quot;&gt;
&lt;li&gt;简洁高效&lt;/li&gt;
&lt;li&gt;处理速度快&lt;/li&gt;
&lt;li&gt;可扩展性强&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; padding: 15px; background: #fff2f2; margin-left: 10px; border-radius: 6px;&quot;&gt;
&lt;h3 style=&quot;color: #cc0000;&quot;&gt;缺点&lt;/h3&gt;
&lt;ul style=&quot;list-style-type: circle; padding-left: 20px;&quot;&gt;
&lt;li&gt;需要理解正则表达式&lt;/li&gt;
&lt;li&gt;可能包含不需要的中文标点&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);&quot;&gt;
&lt;h2 style=&quot;color: #1a2980; border-bottom: 2px solid #26d0ce; padding-bottom: 10px;&quot;&gt;方法2：使用Unicode范围判断&lt;/h2&gt;
&lt;p&gt;通过检查每个字符是否在汉字Unicode范围内来提取汉字。&lt;/p&gt;
&lt;div style=&quot;background: #f5f7ff; padding: 15px; border-left: 4px solid #4e73df; margin: 15px 0; border-radius: 0 8px 8px 0;&quot;&gt;
&lt;pre style=&quot;background: #2d3748; color: #e2e8f0; padding: 15px; border-radius: 6px; overflow: auto; margin: 0; font-family: 'Consolas', monospace;&quot;&gt;
def extract_chinese_unicode(text):
    # 主要汉字Unicode范围
    chinese_chars = []
    for char in text:
        if '\u4e00' &amp;lt;= char &amp;lt;= '\u9fff':
            chinese_chars.append(char)
    return ''.join(chinese_chars)

# 示例用法
text = &quot;Python3编程：学习人工智能和机器学习！2023&quot;
print(extract_chinese_unicode(text))  # 输出: &quot;编程学习人工智能和机器学习&quot;
            &lt;/pre&gt;
&lt;/div&gt;
&lt;h3 style=&quot;color: #1a2980; margin-top: 25px;&quot;&gt;Unicode范围说明&lt;/h3&gt;
&lt;table style=&quot;width: 100%; border-collapse: collapse; margin-top: 15px;&quot;&gt;
&lt;tr style=&quot;background: #1a2980; color: white;&quot;&gt;
&lt;th style=&quot;padding: 10px; text-align: left;&quot;&gt;范围&lt;/th&gt;
&lt;th style=&quot;padding: 10px; text-align: left;&quot;&gt;描述&lt;/th&gt;
&lt;th style=&quot;padding: 10px; text-align: left;&quot;&gt;字符数&lt;/th&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd;&quot;&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;\u4e00-\u62FF&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;常用汉字&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;约6,000个&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd; background: #f8f9fc;&quot;&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;\u6300-\u77FF&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;次常用汉字&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;约3,000个&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd;&quot;&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;\u7800-\u8CFF&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;罕见汉字&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;约3,000个&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd; background: #f8f9fc;&quot;&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;\u8D00-\u9FFF&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;扩展汉字&lt;/td&gt;
&lt;td style=&quot;padding: 10px;&quot;&gt;约2,000个&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);&quot;&gt;
&lt;h2 style=&quot;color: #1a2980; border-bottom: 2px solid #26d0ce; padding-bottom: 10px;&quot;&gt;方法3：使用第三方库&lt;/h2&gt;
&lt;p&gt;对于更复杂的中文处理需求，可以使用专门的NLP库。&lt;/p&gt;
&lt;div style=&quot;background: #f5f7ff; padding: 15px; border-left: 4px solid #4e73df; margin: 15px 0; border-radius: 0 8px 8px 0;&quot;&gt;
&lt;pre style=&quot;background: #2d3748; color: #e2e8f0; padding: 15px; border-radius: 6px; overflow: auto; margin: 0; font-family: 'Consolas', monospace;&quot;&gt;
# 使用jieba分词库提取汉字
import jieba

def extract_chinese_jieba(text):
    # 使用jieba进行分词
    words = jieba.cut(text)
    # 过滤非汉字词语
    chinese_words = [word for word in words if '\u4e00' &amp;lt;= word &amp;lt;= '\u9fff']
    return ''.join(chinese_words)

# 示例用法
text = &quot;自然语言处理(NLP)是人工智能的重要分支。&quot;
print(extract_chinese_jieba(text))  # 输出: &quot;自然语言处理是人工智能的重要分支&quot;
            &lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-top: 25px; background: #e6f7ff; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;color: #0056b3;&quot;&gt;推荐第三方库&lt;/h3&gt;
&lt;ul style=&quot;list-style-type: circle; padding-left: 25px;&quot;&gt;
&lt;li&gt;&lt;strong&gt;jieba&lt;/strong&gt; - 最流行的中文分词工具&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;pyltp&lt;/strong&gt; - 哈工大语言技术平台&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;THULAC&lt;/strong&gt; - 清华大学中文词法分析工具包&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SnowNLP&lt;/strong&gt; - 中文文本处理库&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);&quot;&gt;
&lt;h2 style=&quot;color: #1a2980; border-bottom: 2px solid #26d0ce; padding-bottom: 10px;&quot;&gt;方法对比与选择建议&lt;/h2&gt;
&lt;table style=&quot;width: 100%; border-collapse: collapse; margin-top: 15px;&quot;&gt;
&lt;tr style=&quot;background: #1a2980; color: white;&quot;&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;方法&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;速度&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;准确性&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;适用场景&lt;/th&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;正则表达式&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;快&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;高&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;简单汉字提取&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd; background: #f8f9fc;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;Unicode范围&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;中等&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;高&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;仅需要汉字（不含标点）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #ddd;&quot;&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;第三方库&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;较慢&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;非常高&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;复杂中文处理任务&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;div style=&quot;margin-top: 25px; background: #f0f7ff; padding: 20px; border-radius: 8px; border-left: 4px solid #4e73df;&quot;&gt;
&lt;h3 style=&quot;color: #1a2980;&quot;&gt;选择建议&lt;/h3&gt;
&lt;ul style=&quot;list-style-type: circle; padding-left: 25px;&quot;&gt;
&lt;li&gt;对于&lt;strong&gt;简单文本提取&lt;/strong&gt;，推荐使用正则表达式方法&lt;/li&gt;
&lt;li&gt;当需要&lt;strong&gt;排除所有标点符号&lt;/strong&gt;时，使用Unicode范围方法&lt;/li&gt;
&lt;li&gt;在&lt;strong&gt;自然语言处理&lt;/strong&gt;任务中，使用第三方库效果更好&lt;/li&gt;
&lt;li&gt;处理&lt;strong&gt;大型数据集&lt;/strong&gt;时，优先考虑正则表达式以提升效率&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);&quot;&gt;
&lt;h2 style=&quot;color: #1a2980; border-bottom: 2px solid #26d0ce; padding-bottom: 10px;&quot;&gt;实际应用场景&lt;/h2&gt;
&lt;div style=&quot;display: flex; gap: 20px; margin-top: 20px; flex-wrap: wrap;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #e6f7ff; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;color: #0056b3;&quot;&gt;数据清洗&lt;/h3&gt;
&lt;p&gt;从爬取的网页数据中提取纯中文内容，去除HTML标签、英文和数字。&lt;/p&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #e6f7ff; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;color: #0056b3;&quot;&gt;文本分析&lt;/h3&gt;
&lt;p&gt;在进行词频统计、情感分析前，提取中文文本进行预处理。&lt;/p&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background: #e6f7ff; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;color: #0056b3;&quot;&gt;内容生成&lt;/h3&gt;
&lt;p&gt;从混合文本中提取汉字用于生成纯中文摘要或报告。&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-top: 30px; background: #f5f7ff; padding: 20px; border-radius: 8px; border-left: 4px solid #1a2980;&quot;&gt;
&lt;h3 style=&quot;color: #1a2980;&quot;&gt;注意事项&lt;/h3&gt;
&lt;ul style=&quot;list-style-type: circle; padding-left: 25px;&quot;&gt;
&lt;li&gt;中文标点符号（如，。？！）通常也在Unicode汉字范围内&lt;/li&gt;
&lt;li&gt;某些罕见汉字可能不在基本汉字Unicode范围内&lt;/li&gt;
&lt;li&gt;不同方法对中文数字（如&quot;一&quot;、&quot;二&quot;）的处理结果一致&lt;/li&gt;
&lt;li&gt;繁体字也在基本汉字Unicode范围内&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/section&gt;
</description><pubDate>Tue, 19 Aug 2025 16:04:19 +0800</pubDate></item><item><title>ARM豪掷2500万美金挖角亚马逊芯片核心，自研棋局剑指英伟达腹地</title><link>http://milin.jltcw.com/20258542.html</link><description>&lt;p style=&quot;text-align: center;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://tse1-mm.cn.bing.net/th/id/OIP-C.zIJNek0UuazpbTpTeosfxwAAAA&quot;/&gt;&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  当芯片巨头ARM将一张价值2500万美元的合约推到亚马逊AI芯片主管拉米·辛诺面前时，一场撼动半导体产业格局的人才争夺战正式进入高潮。这位主导亚马逊Trainium和Inferentia芯片开发的关键人物，在经历长达半年的拉锯谈判后，最终选择加盟ARM担任高级副总裁，执掌新组建的200人AI芯片研发团队。这步棋下得狠，也下得准。辛诺在亚马逊期间开发的AI芯片，矛头本就对准英伟达的行业统治地位。如今他转身投入ARM阵营，带来的不仅是技术经验，更是一套直刺数据中心市场的成熟方法论。ARM为此付出的代价不小——500万美元年薪打底，价值2000万美元的限制性股票压阵，外加与产品路线图挂钩的浮动奖金，硅谷顶级人才的价码被重新定义。但ARM显然认为这笔投入划得来。过去几个月，这家靠IP授权吃饭的架构巨头动作频频，不仅从慧与科技挖来系统设计专家尼古拉斯·杜贝，还将英特尔和高通的芯片工程师史蒂夫·哈尔特收入麾下。一支由顶尖技术大脑组成的特种部队已然成型。战略转型的号角早在去年12月就已吹响。当时ARM在一场法律诉讼中意外泄露了自研芯片的野心，今年7月首席执行官雷内·哈斯更公开表态要“超越设计范畴”，将触角伸向芯片制造领域。如今辛诺团队的加入，让模糊的蓝图骤然清晰。转型背后的危机感真实存在。苹果M系列芯片的成功已经证明，顶级客户完全能基于ARM架构自研芯片；高通、英伟达也在悄悄布局定制化架构。继续固守IP授权的老路，终将被釜底抽薪。ARM必须开辟新战场。数据中心市场是哈斯押注的关键筹码。他曾在内部预测，到2025年ARM在数据中心CPU市场的份额要从去年可怜的15%跃升至50%。如此激进的增长目标，没有自研芯片支撑无异于痴人说梦。辛诺的实战经验正好补上关键缺口——他主导的Trainium芯片专攻AI模型训练，Inferentia则聚焦推理优化，两者结合恰是攻坚数据中心的双刃剑。亚马逊的处境因此变得微妙。投入巨资培育的芯片战略突遭核心人员流失，而自家AI芯片尚未在英伟达与AMD的夹击下杀出血路。更关键的是，亚马逊始终没想清楚这些芯片究竟只服务AWS，还是推向公开市场。犹豫之间，人才已被虎视眈眈的对手截走。行业洗牌的征兆已经显现。ARM弃用沿用20年的Cortex品牌，推出Neoverse等五大新产品线绝非偶然。通过计算子系统（CSS）模式，ARM的版税收入较去年同期暴涨100%，16份授权协议背后是商业模式的质变——从按件收费转向深度绑定的系统级分成。当ARM从IP供应商蜕变为芯片设计商，传统产业链条必然重构。RISC-V架构可能迎来意外机遇，长期被巨头垄断的AI芯片战场将涌入新变量。而辛诺的价值，正在于他亲历过从零构建替代英伟达方案的完整周期。不过转型之路绝非坦途。芯片研发的烧钱速度远超IP授权，ARM能否承受与老客户正面竞争的代价？当芯片蓝图化为实体产品，英伟达的CUDA生态岂会坐以待毙？这些问题的答案，或许就藏在ARM为辛诺开出的奖金条款里——那组与产品路线图深度绑定的数字，既是赌注，也是宣言。&lt;/p&gt;</description><pubDate>Tue, 19 Aug 2025 15:27:35 +0800</pubDate></item><item><title>Claude/ChatGPT任你选，苹果扩展Xcode26智能AI代码助手生态</title><link>http://milin.jltcw.com/20258541.html</link><description>&lt;p style=&quot;text-align: center;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://tse3-mm.cn.bing.net/th/id/OIP-C.uSfxk9KavunG5Pf5nDpizAHaEL&quot;/&gt;&lt;/p&gt;&lt;p&gt;&amp;emsp;&amp;emsp;  上周发布的Xcode26Beta7版本在开发者社区投下一枚技术震撼弹——代码库中悄然出现的Claude引用，透露出苹果正将Anthropic的旗舰AI模型深度整合进开发环境。这意味着继ChatGPT之后，开发者即将在原生工作流中解锁第二款顶级AI助手。过去开发者想用Claude辅助编程，总免不了在API密钥配置和插件兼容性上耗费时间，而新版本直接抹平了这些摩擦。在Intelligence模块的底层架构里，代码明确指向对ClaudeSonnet4.0和ClaudeOpus4的支持，这两种模型都以逻辑严谨和安全设计著称，特别适合处理需要高可靠性的系统级编程任务。回想去年WWDC上首次亮相却迟迟未落地的SwiftAssist，苹果显然调整了技术路线。最初的愿景是打造封闭的专属编程助手，如今转向拥抱多元生态。Xcode26的代码库清晰显示，其AI框架已设计为可插拔结构：苹果自研模型负责基础任务，ChatGPT处理创意性需求，Claude专注逻辑严谨场景，开发者甚至能加载本地运行的轻量化模型。这种分层策略既满足代码安全性要求，又保留灵活创新的空间。选择权的下放正在改变开发习惯。硅谷某移动开发团队在测试版中对比发现：用ChatGPT快速生成UI原型，切换Claude优化内存管理逻辑，开发效率提升近40%。而独立开发者更看重本地模型对私有代码的保护能力，在敏感项目中完全断开云服务连接。这种按需调配资源的模式，正在模糊工具与协作者的界限。苹果的AI策略转型值得玩味。从坚持全栈自研到引入第三方顶级模型，折射出实用主义压倒完美主义。内部消息源透露，原定去年推出的SwiftAssist因幻觉问题屡次跳票，迫使团队转向成熟解决方案。这种开放或许会蔓延至其他领域——代码库中某些配置片段暗示，Claude可能即将登陆iOS的写作工具，成为Siri的补充脑区。当业界追逐单一超级模型时，苹果在Xcode26中构建的异构生态提供了新思路。不同模型在代码生成、接口设计、测试用例编写等环节各展所长，开发者不必妥协于某种固定范式。这种多样性恰是创意迸发的土壤，也预示着编程工具将从标准化流水线，进化为人机协作的创意工坊。&lt;/p&gt;</description><pubDate>Tue, 19 Aug 2025 15:15:10 +0800</pubDate></item><item><title>Python值传递与引用传递的区别详解 | Python参数传递机制</title><link>http://milin.jltcw.com/20258540.html</link><description>
&lt;header style=&quot;text-align: center; margin-bottom: 40px; padding: 20px; background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%); border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);&quot;&gt;
&lt;h1 style=&quot;color: white; font-size: 2.5rem; margin-bottom: 10px;&quot;&gt;Python参数传递：值传递与引用传递&lt;/h1&gt;
&lt;p style=&quot;color: rgba(255,255,255,0.9); font-size: 1.2rem; max-width: 700px; margin: 0 auto;&quot;&gt;深入理解Python中函数参数传递的机制，掌握可变与不可变对象的不同行为&lt;/p&gt;
&lt;/header&gt;
&lt;main style=&quot;background-color: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 15px rgba(0,0,0,0.05);&quot;&gt;
&lt;section style=&quot;margin-bottom: 40px;&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;Python参数传递的本质&lt;/h2&gt;
&lt;p style=&quot;line-height: 1.6; font-size: 1.1rem;&quot;&gt;
                在Python中，&lt;strong style=&quot;color: #e74c3c;&quot;&gt;所有参数传递都是&quot;对象引用传递&quot;&lt;/strong&gt;。这意味着传递给函数的是对象的引用（内存地址），而不是对象本身的副本。然而，根据对象类型（可变或不可变），函数内对参数的操作会产生不同的结果：
            &lt;/p&gt;
&lt;ul style=&quot;line-height: 1.6; font-size: 1.1rem; padding-left: 20px;&quot;&gt;
&lt;li&gt;&lt;strong&gt;不可变对象&lt;/strong&gt;（数字、字符串、元组）：函数内修改会创建新对象，不影响原始对象&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;可变对象&lt;/strong&gt;（列表、字典、集合）：函数内修改会影响原始对象&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px;&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;不可变对象示例（类似值传递）&lt;/h2&gt;
&lt;p style=&quot;line-height: 1.6; font-size: 1.1rem;&quot;&gt;
                当传递不可变对象时，函数内部对参数的修改不会影响原始变量，因为操作会创建新对象：
            &lt;/p&gt;
&lt;div style=&quot;background-color: #f1f8ff; padding: 15px; border-radius: 8px; border-left: 4px solid #3498db; margin: 20px 0;&quot;&gt;
&lt;pre style=&quot;margin: 0; overflow-x: auto;&quot;&gt;&lt;code style=&quot;display: block; padding: 15px; font-family: 'Consolas', monospace; font-size: 1rem; line-height: 1.5;&quot;&gt;
def modify_number(x):
    print(&quot;函数内 - 修改前:&quot;, x, id(x))
    x = x + 10  # 创建新对象
    print(&quot;函数内 - 修改后:&quot;, x, id(x))

num = 5
print(&quot;调用前:&quot;, num, id(num))
modify_number(num)
print(&quot;调用后:&quot;, num, id(num))  # 原始值未改变
                &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: #e8f5e9; padding: 20px; border-radius: 8px; margin-top: 20px;&quot;&gt;
&lt;h3 style=&quot;color: #27ae60; margin-top: 0;&quot;&gt;输出结果分析：&lt;/h3&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;调用前: 5 140719415175744&lt;/p&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;函数内 - 修改前: 5 140719415175744&lt;/p&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;函数内 - 修改后: 15 140719415176064&lt;/p&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;调用后: 5 140719415175744&lt;/p&gt;
&lt;p style=&quot;line-height: 1.6; margin-top: 15px;&quot;&gt;
&lt;strong&gt;关键点：&lt;/strong&gt; 函数内部修改创建了新整数对象，原始变量保持不变。内存地址变化证明创建了新对象。
                &lt;/p&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px;&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;可变对象示例（类似引用传递）&lt;/h2&gt;
&lt;p style=&quot;line-height: 1.6; font-size: 1.1rem;&quot;&gt;
                当传递可变对象时，函数内部对参数的修改会影响原始对象：
            &lt;/p&gt;
&lt;div style=&quot;background-color: #f1f8ff; padding: 15px; border-radius: 8px; border-left: 4px solid #3498db; margin: 20px 0;&quot;&gt;
&lt;pre style=&quot;margin: 0; overflow-x: auto;&quot;&gt;&lt;code style=&quot;display: block; padding: 15px; font-family: 'Consolas', monospace; font-size: 1rem; line-height: 1.5;&quot;&gt;
def modify_list(lst):
    print(&quot;函数内 - 修改前:&quot;, lst, id(lst))
    lst.append(4)      # 修改原列表
    lst[0] = 99        # 修改原列表
    print(&quot;函数内 - 修改后:&quot;, lst, id(lst))

my_list = [1, 2, 3]
print(&quot;调用前:&quot;, my_list, id(my_list))
modify_list(my_list)
print(&quot;调用后:&quot;, my_list, id(my_list))  # 原始列表被修改
                &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: #e8f5e9; padding: 20px; border-radius: 8px; margin-top: 20px;&quot;&gt;
&lt;h3 style=&quot;color: #27ae60; margin-top: 0;&quot;&gt;输出结果分析：&lt;/h3&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;调用前: [1, 2, 3] 140258147731648&lt;/p&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;函数内 - 修改前: [1, 2, 3] 140258147731648&lt;/p&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;函数内 - 修改后: [99, 2, 3, 4] 140258147731648&lt;/p&gt;
&lt;p style=&quot;margin: 5px 0; font-family: monospace; font-size: 1rem;&quot;&gt;调用后: [99, 2, 3, 4] 140258147731648&lt;/p&gt;
&lt;p style=&quot;line-height: 1.6; margin-top: 15px;&quot;&gt;
&lt;strong&gt;关键点：&lt;/strong&gt; 函数内部修改影响了原始列表。所有操作使用相同内存地址，证明操作的是同一个对象。
                &lt;/p&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px;&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;重新赋值与就地修改的区别&lt;/h2&gt;
&lt;p style=&quot;line-height: 1.6; font-size: 1.1rem;&quot;&gt;
                理解重新赋值和就地修改的区别至关重要，这解释了为什么有时可变对象也不会被修改：
            &lt;/p&gt;
&lt;div style=&quot;background-color: #f1f8ff; padding: 15px; border-radius: 8px; border-left: 4px solid #3498db; margin: 20px 0;&quot;&gt;
&lt;pre style=&quot;margin: 0; overflow-x: auto;&quot;&gt;&lt;code style=&quot;display: block; padding: 15px; font-family: 'Consolas', monospace; font-size: 1rem; line-height: 1.5;&quot;&gt;
def reassign_list(lst):
    print(&quot;函数内 - 重新赋值前:&quot;, lst, id(lst))
    lst = [10, 20, 30]  # 创建新列表对象
    print(&quot;函数内 - 重新赋值后:&quot;, lst, id(lst))

def modify_list_inplace(lst):
    print(&quot;函数内 - 修改前:&quot;, lst, id(lst))
    lst.append(100)     # 就地修改原列表
    print(&quot;函数内 - 修改后:&quot;, lst, id(lst))

original_list = [1, 2, 3]

print(&quot;=== 重新赋值示例 ===&quot;)
print(&quot;调用前:&quot;, original_list, id(original_list))
reassign_list(original_list)
print(&quot;调用后:&quot;, original_list, id(original_list))  # 原始列表不变

print(&quot;\n=== 就地修改示例 ===&quot;)
print(&quot;调用前:&quot;, original_list, id(original_list))
modify_list_inplace(original_list)
print(&quot;调用后:&quot;, original_list, id(original_list))  # 原始列表被修改
                &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: #fff8e1; padding: 20px; border-radius: 8px; margin-top: 20px;&quot;&gt;
&lt;h3 style=&quot;color: #f39c12; margin-top: 0;&quot;&gt;关键区别：&lt;/h3&gt;
&lt;ul style=&quot;line-height: 1.6;&quot;&gt;
&lt;li&gt;&lt;strong&gt;重新赋值&lt;/strong&gt; (=操作) 会创建新对象，断开与原始对象的联系&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;就地修改&lt;/strong&gt; (append, extend, 直接元素赋值等) 会修改原始对象&lt;/li&gt;
&lt;li&gt;内存地址变化表明创建了新对象，内存地址不变表明修改原对象&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px;&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;Python中的对象分类&lt;/h2&gt;
&lt;div style=&quot;display: flex; flex-wrap: wrap; gap: 20px; margin-top: 20px;&quot;&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background-color: #e3f2fd; padding: 20px; border-radius: 8px; border-top: 4px solid #2196f3;&quot;&gt;
&lt;h3 style=&quot;color: #1976d2; margin-top: 0;&quot;&gt;不可变对象&lt;/h3&gt;
&lt;ul style=&quot;line-height: 1.6; padding-left: 20px;&quot;&gt;
&lt;li&gt;数字类型：int, float, complex&lt;/li&gt;
&lt;li&gt;字符串：str&lt;/li&gt;
&lt;li&gt;字节：bytes&lt;/li&gt;
&lt;li&gt;元组：tuple&lt;/li&gt;
&lt;li&gt;布尔：bool&lt;/li&gt;
&lt;li&gt;冻结集合：frozenset&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;background-color: #bbdefb; padding: 10px; border-radius: 5px;&quot;&gt;
                        函数内修改会创建新对象，原始对象不变
                    &lt;/p&gt;
&lt;/div&gt;
&lt;div style=&quot;flex: 1; min-width: 250px; background-color: #ffebee; padding: 20px; border-radius: 8px; border-top: 4px solid #f44336;&quot;&gt;
&lt;h3 style=&quot;color: #d32f2f; margin-top: 0;&quot;&gt;可变对象&lt;/h3&gt;
&lt;ul style=&quot;line-height: 1.6; padding-left: 20px;&quot;&gt;
&lt;li&gt;列表：list&lt;/li&gt;
&lt;li&gt;字典：dict&lt;/li&gt;
&lt;li&gt;集合：set&lt;/li&gt;
&lt;li&gt;字节数组：bytearray&lt;/li&gt;
&lt;li&gt;用户自定义类实例&lt;/li&gt;
&lt;/ul&gt;
&lt;p style=&quot;background-color: #ffcdd2; padding: 10px; border-radius: 5px;&quot;&gt;
                        函数内就地修改会影响原始对象
                    &lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;margin-bottom: 40px;&quot;&gt;
&lt;h2 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;实际应用建议&lt;/h2&gt;
&lt;div style=&quot;background-color: #e8f5e9; padding: 20px; border-radius: 8px;&quot;&gt;
&lt;h3 style=&quot;color: #2e7d32; margin-top: 0;&quot;&gt;最佳实践&lt;/h3&gt;
&lt;ul style=&quot;line-height: 1.6; padding-left: 20px;&quot;&gt;
&lt;li&gt;需要避免函数修改原始数据时，使用不可变对象&lt;/li&gt;
&lt;li&gt;需要修改原始数据时，使用可变对象&lt;/li&gt;
&lt;li&gt;不想修改原始可变对象时，创建副本：
                        &lt;ul&gt;
&lt;li&gt;&lt;code&gt;new_list = old_list.copy()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;new_dict = old_dict.copy()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;new_set = old_set.copy()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;使用&lt;code&gt;copy.deepcopy()&lt;/code&gt;处理嵌套对象&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;在函数文档中明确说明是否会修改传入的参数&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;margin-top: 20px; background-color: #c8e6c9; padding: 15px; border-radius: 5px;&quot;&gt;
&lt;h4 style=&quot;color: #388e3c; margin-top: 0;&quot;&gt;示例：安全地处理列表&lt;/h4&gt;
&lt;pre style=&quot;margin: 0; overflow-x: auto;&quot;&gt;&lt;code style=&quot;display: block; padding: 15px; font-family: 'Consolas', monospace; font-size: 1rem; line-height: 1.5;&quot;&gt;
def safe_modify(data):
    &quot;&quot;&quot;处理列表数据但不修改原始列表&quot;&quot;&quot;
    # 创建副本进行操作
    working_copy = data.copy()
    working_copy.append(&quot;安全修改&quot;)
    working_copy[0] = 100
    return working_copy

original = [1, 2, 3]
result = safe_modify(original)
print(&quot;原始列表:&quot;, original)  # [1, 2, 3]
print(&quot;处理结果:&quot;, result)    # [100, 2, 3, '安全修改']
                    &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section style=&quot;background-color: #e0f7fa; padding: 25px; border-radius: 8px; border-left: 5px solid #00bcd4;&quot;&gt;
&lt;h2 style=&quot;color: #00838f; margin-top: 0;&quot;&gt;总结：Python参数传递机制&lt;/h2&gt;
&lt;table style=&quot;width: 100%; border-collapse: collapse; margin-top: 20px;&quot;&gt;
&lt;thead&gt;
&lt;tr style=&quot;background-color: #00bcd4; color: white;&quot;&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;关键点&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left;&quot;&gt;说明&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr style=&quot;border-bottom: 1px solid #b2ebf2;&quot;&gt;
&lt;td style=&quot;padding: 12px; font-weight: bold;&quot;&gt;传递机制&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;对象引用传递（传递内存地址）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #b2ebf2;&quot;&gt;
&lt;td style=&quot;padding: 12px; font-weight: bold;&quot;&gt;不可变对象&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;类似值传递效果（函数内修改创建新对象）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #b2ebf2;&quot;&gt;
&lt;td style=&quot;padding: 12px; font-weight: bold;&quot;&gt;可变对象&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;类似引用传递效果（函数内就地修改影响原对象）&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;border-bottom: 1px solid #b2ebf2;&quot;&gt;
&lt;td style=&quot;padding: 12px; font-weight: bold;&quot;&gt;重新赋值&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;创建新对象，不影响原始对象&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 12px; font-weight: bold;&quot;&gt;最佳实践&lt;/td&gt;
&lt;td style=&quot;padding: 12px;&quot;&gt;根据需求选择对象类型，需要保护原始数据时使用副本&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div style=&quot;margin-top: 25px; background-color: #00bcd4; color: white; padding: 15px; border-radius: 5px;&quot;&gt;
&lt;p style=&quot;margin: 0; font-size: 1.1rem;&quot;&gt;
&lt;strong&gt;核心原则：&lt;/strong&gt; Python中一切皆对象，函数参数传递的是对象引用。要改变函数外部的变量，要么使用可变对象并进行就地修改，要么返回新值并重新赋值。
                &lt;/p&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/main&gt;
&lt;footer style=&quot;text-align: center; margin-top: 40px; color: #7f8c8d; font-size: 0.9rem;&quot;&gt;
&lt;p&gt;© 2023 Python参数传递教程 | 理解值传递与引用传递的区别&lt;/p&gt;
&lt;/footer&gt;
</description><pubDate>Tue, 19 Aug 2025 15:08:37 +0800</pubDate></item><item><title>Python关闭当前进程的5种方法 - 完整教程 | Python编程指南</title><link>http://milin.jltcw.com/20258539.html</link><description>
&lt;h1 style=&quot;color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;&quot;&gt;Python关闭当前进程的5种方法详解&lt;/h1&gt;
&lt;div style=&quot;background: #e8f4f8; padding: 15px; border-left: 4px solid #3498db; margin-bottom: 20px;&quot;&gt;
&lt;p style=&quot;margin: 0;&quot;&gt;在Python开发中，有时需要主动终止程序运行。本文将全面介绍5种关闭当前进程的方法，包括它们的适用场景、差异以及代码实现。&lt;/p&gt;
&lt;/div&gt;
&lt;h2 style=&quot;color: #2980b9;&quot;&gt;为什么需要主动关闭Python进程？&lt;/h2&gt;
&lt;p&gt;主动关闭进程在以下场景中非常有用：&lt;/p&gt;
&lt;ul style=&quot;background: #f9f9f9; padding: 15px 15px 15px 35px; border-radius: 5px;&quot;&gt;
&lt;li&gt;程序完成所有任务后正常退出&lt;/li&gt;
&lt;li&gt;遇到不可恢复的错误时终止程序&lt;/li&gt;
&lt;li&gt;满足特定条件时提前结束执行&lt;/li&gt;
&lt;li&gt;资源清理和释放&lt;/li&gt;
&lt;li&gt;控制多进程应用程序&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;color: #2980b9; margin-top: 30px;&quot;&gt;方法1：使用sys.exit() - 推荐的标准方法&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;sys.exit()&lt;/code&gt; 是最常用的退出Python程序的方式，它会引发SystemExit异常，可以被捕获处理。&lt;/p&gt;
&lt;div style=&quot;background: #2c3e50; color: #ecf0f1; padding: 12px; border-radius: 5px 5px 0 0; font-weight: bold;&quot;&gt;代码示例：sys.exit()的基本用法&lt;/div&gt;
&lt;pre style=&quot;background: #f8f8f8; padding: 15px; border: 1px solid #ddd; border-top: none; margin-top: 0; overflow: auto;&quot;&gt;
&lt;code&gt;import sys

def main():
    try:
        print(&quot;程序开始执行...&quot;)
        # 满足条件时退出
        if some_condition:
            sys.exit(&quot;提前退出程序&quot;)
        print(&quot;程序继续执行...&quot;)
    except SystemExit as e:
        print(f&quot;捕获到退出信号: {e}&quot;)
        # 执行清理操作
        sys.exit(e.code)

if __name__ == &quot;__main__&quot;:
    main()
    print(&quot;此消息不会显示，因为程序已退出&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;background: #e8f4f8; padding: 15px; border-radius: 5px; margin-top: 15px;&quot;&gt;
&lt;p style=&quot;margin: 0;&quot;&gt;&lt;strong&gt;特点：&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;推荐的标准退出方式&lt;/li&gt;
&lt;li&gt;可以传递退出状态码（0表示成功，非0表示错误）&lt;/li&gt;
&lt;li&gt;会触发finally块和清理操作&lt;/li&gt;
&lt;li&gt;可以被捕获处理&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 style=&quot;color: #2980b9; margin-top: 30px;&quot;&gt;方法2：使用os._exit() - 立即终止进程&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;os._exit()&lt;/code&gt; 会立即终止程序，不执行任何清理操作，适用于子进程退出等特殊场景。&lt;/p&gt;
&lt;div style=&quot;background: #2c3e50; color: #ecf0f1; padding: 12px; border-radius: 5px 5px 0 0; font-weight: bold;&quot;&gt;代码示例：os._exit()的使用&lt;/div&gt;
&lt;pre style=&quot;background: #f8f8f8; padding: 15px; border: 1px solid #ddd; border-top: none; margin-top: 0; overflow: auto;&quot;&gt;
&lt;code&gt;import os
import sys

try:
    print(&quot;此消息会显示&quot;)
    # 立即退出，不执行清理
    os._exit(1)
    print(&quot;此消息不会显示&quot;)
except:
    print(&quot;异常不会被捕获&quot;)
finally:
    print(&quot;finally块不会执行&quot;)

# 后续代码都不会执行&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;background: #e8f4f8; padding: 15px; border-radius: 5px; margin-top: 15px;&quot;&gt;
&lt;p style=&quot;margin: 0;&quot;&gt;&lt;strong&gt;使用场景：&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;在子进程中需要立即退出时&lt;/li&gt;
&lt;li&gt;程序处于不稳定状态需要强制终止&lt;/li&gt;
&lt;li&gt;避免执行清理操作的场景&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 style=&quot;color: #2980b9; margin-top: 30px;&quot;&gt;方法3：使用raise SystemExit - 替代sys.exit()&lt;/h2&gt;
&lt;p&gt;直接引发SystemExit异常与调用sys.exit()效果相同，但更显式。&lt;/p&gt;
&lt;div style=&quot;background: #2c3e50; color: #ecf0f1; padding: 12px; border-radius: 5px 5px 0 0; font-weight: bold;&quot;&gt;代码示例：raise SystemExit&lt;/div&gt;
&lt;pre style=&quot;background: #f8f8f8; padding: 15px; border: 1px solid #ddd; border-top: none; margin-top: 0; overflow: auto;&quot;&gt;
&lt;code&gt;def process_data(data):
    if not data:
        # 等同于sys.exit()
        raise SystemExit(&quot;错误：无数据可处理&quot;)
    
    print(&quot;处理数据...&quot;)

try:
    process_data([])
except SystemExit as e:
    print(f&quot;程序退出: {e}&quot;)
    # 执行资源清理
    sys.exit(1)&lt;/code&gt;&lt;/pre&gt;
&lt;h2 style=&quot;color: #2980b9; margin-top: 30px;&quot;&gt;方法4：使用quit()和exit() - 交互式环境专用&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;quit()&lt;/code&gt; 和 &lt;code&gt;exit()&lt;/code&gt; 主要用于交互式环境，不推荐在脚本中使用。&lt;/p&gt;
&lt;div style=&quot;background: #2c3e50; color: #ecf0f1; padding: 12px; border-radius: 5px 5px 0 0; font-weight: bold;&quot;&gt;代码示例：quit()和exit()&lt;/div&gt;
&lt;pre style=&quot;background: #f8f8f8; padding: 15px; border: 1px solid #ddd; border-top: none; margin-top: 0; overflow: auto;&quot;&gt;
&lt;code&gt;# 在Python解释器中
&amp;gt;&amp;gt;&amp;gt; print(&quot;Hello&quot;)
Hello
&amp;gt;&amp;gt;&amp;gt; quit()  # 退出解释器

# 在脚本中使用（不推荐）
def main():
    print(&quot;程序开始&quot;)
    if error_occurred:
        exit(1)  # 可能产生意外行为
    print(&quot;程序结束&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;background: #fef9e7; padding: 15px; border-left: 4px solid #f1c40f; margin-top: 15px;&quot;&gt;
&lt;p style=&quot;margin: 0;&quot;&gt;&lt;strong&gt;注意：&lt;/strong&gt;在生产脚本中避免使用quit()和exit()，它们依赖于site模块，可能在非交互环境中不可用。&lt;/p&gt;
&lt;/div&gt;
&lt;h2 style=&quot;color: #2980b9; margin-top: 30px;&quot;&gt;方法5：使用子进程终止 - 外部控制&lt;/h2&gt;
&lt;p&gt;通过操作系统的进程管理功能终止Python进程。&lt;/p&gt;
&lt;div style=&quot;background: #2c3e50; color: #ecf0f1; padding: 12px; border-radius: 5px 5px 0 0; font-weight: bold;&quot;&gt;代码示例：终止当前进程&lt;/div&gt;
&lt;pre style=&quot;background: #f8f8f8; padding: 15px; border: 1px solid #ddd; border-top: none; margin-top: 0; overflow: auto;&quot;&gt;
&lt;code&gt;import os
import signal

# 获取当前进程ID
current_pid = os.getpid()

try:
    # 发送SIGTERM信号
    os.kill(current_pid, signal.SIGTERM)
except Exception as e:
    print(f&quot;终止进程失败: {e}&quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;background: #e8f4f8; padding: 15px; border-radius: 5px; margin-top: 15px;&quot;&gt;
&lt;p style=&quot;margin: 0;&quot;&gt;&lt;strong&gt;适用场景：&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;需要发送特定信号给进程&lt;/li&gt;
&lt;li&gt;外部进程管理需求&lt;/li&gt;
&lt;li&gt;需要完全控制终止行为&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 style=&quot;color: #2980b9; margin-top: 30px;&quot;&gt;方法对比总结&lt;/h2&gt;
&lt;table style=&quot;width: 100%; border-collapse: collapse; background: white; margin-bottom: 20px;&quot;&gt;
&lt;tr style=&quot;background: #3498db; color: white;&quot;&gt;
&lt;th style=&quot;padding: 12px; text-align: left; border: 1px solid #2980b9;&quot;&gt;方法&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left; border: 1px solid #2980b9;&quot;&gt;清理操作&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left; border: 1px solid #2980b9;&quot;&gt;可捕获&lt;/th&gt;
&lt;th style=&quot;padding: 12px; text-align: left; border: 1px solid #2980b9;&quot;&gt;推荐场景&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;sys.exit()&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;是&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;是&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;大多数情况&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;background: #f9f9f9;&quot;&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;os._exit()&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;否&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;否&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;子进程、紧急退出&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;raise SystemExit&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;是&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;是&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;显式退出&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&quot;background: #f9f9f9;&quot;&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;quit()/exit()&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;是&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;是&lt;/td&gt;
&lt;td style=&quot;padding: 10px; border: 1px solid #ddd;&quot;&gt;仅交互环境&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;h2 style=&quot;color: #2980b9; margin-top: 30px;&quot;&gt;最佳实践建议&lt;/h2&gt;
&lt;div style=&quot;background: #f9f9f9; padding: 20px; border-radius: 5px;&quot;&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;优先使用sys.exit()&lt;/strong&gt; - 最标准、最安全的方法&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;子进程退出使用os._exit()&lt;/strong&gt; - 避免资源泄漏&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;始终提供退出状态码&lt;/strong&gt; - 0表示成功，非0表示错误&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;在退出前清理资源&lt;/strong&gt; - 使用try/finally或上下文管理器&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;避免在生产代码中使用quit()/exit()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;处理未捕获的异常&lt;/strong&gt; - 使用sys.excepthook&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-top: 30px; padding: 20px; background: #d5f5e3; border-radius: 5px;&quot;&gt;
&lt;h3 style=&quot;color: #27ae60; margin-top: 0;&quot;&gt;总结&lt;/h3&gt;
&lt;p&gt;在Python中关闭当前进程有多种方法，每种方法都有其适用场景：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;大多数情况下应使用 &lt;code&gt;sys.exit()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;子进程退出或紧急情况使用 &lt;code&gt;os._exit()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;交互式环境使用 &lt;code&gt;quit()&lt;/code&gt; 或 &lt;code&gt;exit()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;显式退出可以使用 &lt;code&gt;raise SystemExit&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;理解这些方法的区别和适用场景，可以帮助你编写更健壮、更易维护的Python应用程序。&lt;/p&gt;
&lt;/div&gt;
</description><pubDate>Tue, 19 Aug 2025 15:03:59 +0800</pubDate></item></channel></rss>