【发布时间】:2019-01-02 21:27:04
【问题描述】:
我正在制作一个小程序,我可以使用它的默认编辑器从计算机的任何部分打开文件。这是我的代码:
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]作为 args 传递,而是将 ["xdg-open"]` 作为 args 传递,file_name作为 bufsize 传递。 -
@abarnert 那我应该通过什么?
-
@mahir,他的意思是像这样使用
callprint(subprocess.call(["xdg-open"], file_name)) -
@abarnert,我确实看到了,但我认为stackoverflow.com/questions/34156193/… 更好地解决了这个问题。
标签: python linux python-3.x