我想通过另一个程序运行python程序first.py
,并使用webdriver
element
这样做将subprocess
作为参数传递:
driver = webdriver.Firefox(executable_path="geckodriver.exe")
process = subprocess.Popen(["python.exe", 'first.py', driver], shell=False)
但是python拒绝将webdriver element
作为argoument
传递
并给出此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\bo\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/bo/Desktop/instagrambot/run_bot.py", line 23, in <lambda>
run_button = tk.Button(root , text="Run", command=lambda: Run())
File "C:/Users/bo/Desktop/instagrambot/run_bot.py", line 12, in Run
close_fds=True)
File "C:\Users\bo\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\bo\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1119, in _execute_child
args = list2cmdline(args)
File "C:\Users\bo\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 530, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'WebDriver' is not iterable
我正在使用Windows 10和python 3.7
答案 0 :(得分:0)
resource_folder_cache
调用的参数应该是字符串,而您正在传递Python对象。这就是为什么会出现迭代错误的原因-Python尝试解析字符串参数(用空格或制表符分隔),并在获取Python对象时失败。
很遗憾,您必须重新考虑您的策略。您可以在subprocess.Popen
模块中构造driver
,也可以有一个单独的Python模块,可以在执行first.py
模块时导入该Python模块以建立driver
。