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

2022-09-15 10:45:03 +08:00
 jtsr

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

3787 次点击
所在节点    Python
35 条回复
abc612008
2022-09-15 10:46:18 +08:00
parts
wudicgi
2022-09-15 10:50:21 +08:00
parts 就不错

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

比如 res 可以是
result
resource
resolution
response
……
Leviathann
2022-09-15 10:51:26 +08:00
words
Akitora
2022-09-15 10:51:55 +08:00
idea 叫它 split ,那就 split 吧
gydi
2022-09-15 10:52:35 +08:00
line_iter
cmdOptionKana
2022-09-15 10:52:51 +08:00
按照英语来说,line = lines.split('\n') 或 words = line.split(' ')
Zenyet
2022-09-15 10:52:56 +08:00
splitteds ? 。。。😂
aaniao002
2022-09-15 11:15:20 +08:00
无脑加 s
optional
2022-09-15 11:21:53 +08:00
看你业务含义啊,
Jirajine
2022-09-15 11:26:40 +08:00
这种临时变量命名宜短不宜长
jorneyr
2022-09-15 11:42:31 +08:00
split 得到的数组业务用途是啥,最好名字和业务术语相关。
wentx
2022-09-15 11:43:59 +08:00
一样一样,splits
bianjp
2022-09-15 11:51:38 +08:00
pieces
likunyan
2022-09-15 11:55:37 +08:00
what is lst
Runtime3
2022-09-15 11:57:27 +08:00
line.split(' ').var ,自动生成,差球不多就行
oneisall8955
2022-09-15 11:59:32 +08:00
xxxSplit
MoYi123
2022-09-15 12:05:04 +08:00
line.split(' ') 当然是 words
calmzhu
2022-09-15 12:20:42 +08:00
中间临时变量全部...
_
__
___
licoycn
2022-09-15 12:58:07 +08:00
xxxList
xxxArr
xxxs
xxxTemp
CrazyRundong
2022-09-15 13:29:38 +08:00
我的习惯是按照被拆分后元素自身的含义命名:
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://www.v2ex.com/t/880180

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

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

© 2021 V2EX