简体   繁体   English

列表python 3中的单独元素,不带[]或(),不带换行

[英]Separate elements in a list python 3 without [] or (), without new line

I need to pass options to rsync. 我需要将选项传递给rsync。 I do that with 我这样做

EXCLUDE = [".svn",".dropbox"]
OPTS = "-rltgoi --delay-updates --delete --exclude={:} --chmod=a-w".format(EXCLUDE)

this code prints 此代码打印

-rltgoi --delay-updates --delete --exclude=['.svn', '.dropbox'] --chmod=a-w

[] can't be processed by the shell []无法由外壳处理

I need to pass 我需要通过

-rltgoi --delay-updates --delete --exclude=.svn,.dropbox --chmod=a-w

You need to join EXCLUDE into a comma-separated string: 您需要将EXCLUDE连接到以逗号分隔的字符串中:

EXCLUDE = ','.join(EXCLUDE)

You are instead interpolating the list representation, which is not what you want here (note that a list representation includes quoted string values as well). 相反,您是插值列表表示形式,这不是您想要的(请注意,列表表示形式还包括带引号的字符串值)。

在将排除项添加到命令之前,应将其加入字符串中。

OPTS = "-rltgoi --delay-updates --delete --exclude={0} --chmod=a-w".format(",".join(EXCLUDE))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM