我正在制作一个小程序,可以使用默认编辑器打开计算机上任何位置的文件。这是我的代码:
from os import *
import subprocess
print("Welcome to my File Finder. Here you can search for a file and open it.")
file_name = str(input("Your file's name:"))
print(subprocess.call(["xdg-open"], file_name))]
但是它没有打开,而是返回了以下错误:
Traceback (most recent call last):
File "Important_tester_projects.py", line 6, in <module>
print(subprocess.call(["xdg-open"], file_name))
File "/usr/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.6/subprocess.py", line 609, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
我已经谷歌搜索了这个错误的解决方案,但是我找不到任何一个似乎可以解决我的问题。该如何修复我的错误?
注意:我的Linux操作系统使用XFCE而不是Gnome。
["xdg-open", file_name]
,但你传入了["xdg-open"]
作为参数,并将file_name
作为缓冲区大小。 - abarnertprint(subprocess.call(["xdg-open", file_name]))
。 - aydow