根据PEP324,我正在尝试应用subprocess.call而不是os.system
在打开多个urls的任务中
import subprocess
open_chromes = [
'https://en.wikipedia.org/wiki/Embodied_cognition',
'https://docs.python.org/3.6/index.html',
'https://docs.djangoproject.com/en/1.11/',]
for chrome in open_chromes:
cmd = ['open', '-na', 'Google Chrome']
subprocess.call(cmd.append(chrome))错误报告为
TypeError: 'NoneType' object is not iterable或者,使用os.system是非常简单的。
import os
open_chromes = [
'https://en.wikipedia.org/wiki/Embodied_cognition',
'https://docs.python.org/3.6/index.html',
'https://docs.djangoproject.com/en/1.11/',]
for chrome in open_chromes:
os.system('open -na "Google Chrome" {}'.format(chrome))我的代码有什么问题?
发布于 2018-01-17 10:01:04
list的append函数不返回任何内容,所以subprocess.call(cmd.append(chrome))等同于subprocess.call(None),这就是问题所在。在进行调用之前,您需要追加
发布于 2021-08-16 08:33:28
如果您希望将其保留为一行,并且不更改原始数组-请使用+运算符
subprocess.call(cmd + chrome)https://stackoverflow.com/questions/48292555
复制相似问题