当前位置:网站首页>nametuple的源码为什么要使用.replace(‘,‘, ‘ ‘).split()而不是.split(‘,‘)
nametuple的源码为什么要使用.replace(‘,‘, ‘ ‘).split()而不是.split(‘,‘)
2022-06-21 06:00:00 【Channing Lewis】

最近在看Python的collections包的nametuple源码,看到两行对字符串的操作:
if isinstance(field_names, str):
field_names = field_names.replace(',', ' ').split()
觉得好奇,如果想用逗号分割字符串的话,直接写:
field_names = field_names.split(',')
就好了。
后来才意识到是为了兼容通过空格分割的情形。源码的写法既可以根据逗号分割也可以通过空格分割,而且可以混合;而我的写法只支持逗号分割。
边栏推荐
- 模块 14 - 15:网络应用通信考试
- 三维引擎软件Vizard入门
- lambda-stream
- 【【毕业季·进击的技术er】------老学长心得分享
- Dual tone search: array is incremented first and then decremented
- Asp. Net web API 2 Lesson 18 - working with entity relations in OData
- Aurora8B10B IP使用 -04- IP例程应用实例
- Aurora8B10B IP使用 -03- IP配置应用指南
- Module 14 - 15: network application communication test
- tf.compat.v1.pad
猜你喜欢

Basic operation of binary sort tree

contos7 安装svn服务端

IP - RF data converter -04- API User Guide - system settings related functions

【【毕业季·进击的技术er】------老学长心得分享

Improved Object Categorization and Detection Using Comparative Object Similarity

Memorizing Normality to Detect Anomaly: Memory-augmented Deep Autoencoder for Unsupervised Anomaly D

Aurora8B10B IP使用 -02- IP功能設計技巧

FPGA - 7 Series FPGA selectio -06- odelay of logic resources

【JVM】 类加载器(ClassLoader)

Account1 is not in the sudoers file. The matter will be reported.
随机推荐
Leetcode question brushing - (4) the first unique character in the string
Do you want to manually implement CSDN dark mode for web page '?
398 hash table (242. valid alphabetic words & 349. intersection of two arrays & 202. happy numbers)
Q & A: issues related to "micro build low code" billing
tf. compat. v1.global_ variables_ initializer
[MYSQL] MYSQL文件结构,页与行记录
Microbial ecological sequencing analysis -- CCA analysis
Sub-Category Optimization for Multi-View Multi-Pose Object Detection
二叉排序树的基本操作
【数据挖掘】期末复习 第二章
Basic operation of binary sort tree
Aurora8B10B IP使用 -03- IP配置应用指南
Error running code generator file: the server time zone value ' й ��� ʱ ��‘ is unrecognized or represents more than one time
Quartz. Net getting started
Picture steganography: Method 1
复制 代码生成器 生成的代码到idea中,运行后网址报错怎么解决
Improved Object Categorization and Detection Using Comparative Object Similarity
牛客-TOP101-BM25
成立时间用了时间插件,但在网页上修改参数的时候,如果未修改时间第一次保存会报错,第二次才行
Leetcode刷题 ——— (4)字符串中的第一个唯一字符