Python 3.x 这个python函数背后的逻辑是什么?
我从一个像这样的朋友那里查看了一个本地python3函数Python 3.x 这个python函数背后的逻辑是什么?,python-3.x,Python 3.x,我从一个像这样的朋友那里查看了一个本地python3函数 from pathlib import Path def link(entries, perm, base="/"): return [y for x in (('-B', f'{entry[1]}:' + f'{"" if base is Path(entry[0]).root else base}' + f'{entry[0]}:{perm}')
from pathlib import Path
def link(entries, perm, base="/"):
return [y for x in
(('-B', f'{entry[1]}:' + f'{"" if base is Path(entry[0]).root else base}' + f'{entry[0]}:{perm}')
for entry in entries) for y in x]
entries = [('a', '/x/y/z'), ('b', './w/s')]
perm = 'ro'
print(link(entries, perm))
['-B', '/x/y/z:/a:ro', '-B', './w/s:/b:ro']
我的问题是y代表x,而某物代表y代表x
背后的逻辑是什么。输出对我来说是有意义的,但我不明白为什么他必须使用y和x
索引?1)something
是一个嵌套序列;第一个循环将内部序列放入x
,第二个循环将这些内部序列中的值放入y
。2) 如果base是Path(条目[0])。root是错误的。切勿将字符串与is
进行比较。如果base==Path(条目[0]),则使用。root
。