大家平时都怎么命名 split 后的变量

2022 年 9 月 15 日
 jtsr

比如 for line in f.readlines(): 第一种 line = line.split(' ') 第二种 line_lst = line.split(' ') 第三种 res = line.split(' ') or other

4851 次点击
所在节点    Python
35 条回复
abc612008
2022 年 9 月 15 日
parts
wudicgi
2022 年 9 月 15 日
parts 就不错

另外不建议用 lst, res 这种缩写

比如 res 可以是
result
resource
resolution
response
……
Leviathann
2022 年 9 月 15 日
words
Akitora
2022 年 9 月 15 日
idea 叫它 split ,那就 split 吧
gydi
2022 年 9 月 15 日
line_iter
cmdOptionKana
2022 年 9 月 15 日
按照英语来说,line = lines.split('\n') 或 words = line.split(' ')
Zenyet
2022 年 9 月 15 日
splitteds ? 。。。😂
aaniao002
2022 年 9 月 15 日
无脑加 s
optional
2022 年 9 月 15 日
看你业务含义啊,
Jirajine
2022 年 9 月 15 日
这种临时变量命名宜短不宜长
jorneyr
2022 年 9 月 15 日
split 得到的数组业务用途是啥,最好名字和业务术语相关。
wentx
2022 年 9 月 15 日
一样一样,splits
bianjp
2022 年 9 月 15 日
pieces
QKgf555H87Fp0cth
2022 年 9 月 15 日
what is lst
Runtime3
2022 年 9 月 15 日
line.split(' ').var ,自动生成,差球不多就行
itechify
2022 年 9 月 15 日
xxxSplit
MoYi123
2022 年 9 月 15 日
line.split(' ') 当然是 words
calmzhu
2022 年 9 月 15 日
中间临时变量全部...
_
__
___
licoycn
2022 年 9 月 15 日
xxxList
xxxArr
xxxs
xxxTemp
CrazyRundong
2022 年 9 月 15 日
我的习惯是按照被拆分后元素自身的含义命名:
rule_type, rule_arg, destination = "DOMAIN-NAME,google.com,Outside".split(",")

如果没有特别指涉的字符串就叫 tokens:
tokens = "foo,bar,baz".split(",")
for token in tokens:
...

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/880180

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX