python 以数组格式打印字符串

发布于 2025-01-02 09:15:54 字数 761 浏览 0 评论 0原文

我将一个参数传递给像 -b bench 这样的 python 脚本。 bench 是这样创建的:

bench_dir = '~/myFD/'
bench_bin = bench_dir + 'src/bin/Assembler'
bench_inp1 = bench_dir + 'input/in.fa'
bench_out1 = bench_dir + 'output/data.scratch'

bench= LiveProcess()
bench.executable = bench_bin
bench.cwd = bench_dir
bench.cmd = [bench.executable] + ['-s', bench_out1, '<', bench_inp1]

bench.cmd 应该看起来像:

~/myFD/src/bin/Assembler -s ~/myFD/output/data.scratch < ~/myFD/input/in.fa

为此,我使用 print bench.cmd 但它没有' t 正确显示上述陈述。相反,它显示:

['~/myFD/src/bin/Assembler', '-s', '~/myFD/output/data.scratch', ' < ', '~/myFD/input/in.fa']

我该如何解决这个问题?

I passed an argument to a python script like -b bench. The bench is created like this:

bench_dir = '~/myFD/'
bench_bin = bench_dir + 'src/bin/Assembler'
bench_inp1 = bench_dir + 'input/in.fa'
bench_out1 = bench_dir + 'output/data.scratch'

bench= LiveProcess()
bench.executable = bench_bin
bench.cwd = bench_dir
bench.cmd = [bench.executable] + ['-s', bench_out1, '<', bench_inp1]

The bench.cmd should looks like:

~/myFD/src/bin/Assembler -s ~/myFD/output/data.scratch < ~/myFD/input/in.fa

to do that, I use print bench.cmd but it doesn't show the above statment correctly. Instead it shows:

['~/myFD/src/bin/Assembler', '-s', '~/myFD/output/data.scratch', ' < ', '~/myFD/input/in.fa']

how can I fix that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情未る 2025-01-09 09:15:54

尝试:print ' '.join(bench.cmd)。这将连接列表并使用空格作为分隔符

Try: print ' '.join(bench.cmd). This joins the list and uses a space as delimiter

兮颜 2025-01-09 09:15:54

您可以执行' '.join(bench.cmd)

You could do ' '.join(bench.cmd).

做个ˇ局外人 2025-01-09 09:15:54

连接的情况:' '.join(bench.cmd)

case for join: ' '.join(bench.cmd)

难得心□动 2025-01-09 09:15:54

您是在寻找这个,

>>> mylist = ['~/myFD/src/bin/Assembler', '-s', '~/myFD/output/data.scratch', ' < ', '~/myFD/input/in.fa']
>>> " ".join(mylist)
'~/myFD/src/bin/Assembler -s ~/myFD/output/data.scratch  <  ~/myFD/input/in.fa'

还是只是连接字符串

bench.cmd = bench.executable + ' -s ' + bench_out1 + ' < ' + bench_inp1

Are you looking for this,

>>> mylist = ['~/myFD/src/bin/Assembler', '-s', '~/myFD/output/data.scratch', ' < ', '~/myFD/input/in.fa']
>>> " ".join(mylist)
'~/myFD/src/bin/Assembler -s ~/myFD/output/data.scratch  <  ~/myFD/input/in.fa'

or just concatenate your strings

bench.cmd = bench.executable + ' -s ' + bench_out1 + ' < ' + bench_inp1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文