Skip to content Skip to sidebar Skip to footer

Python Xdg-open()

Trying to use xdg-open in a python script xdg-open test.mp4 but get the following error: File 'dl.py', line 21 xdg-open test.mp4 ^ SyntaxError: invalid syntax

Solution 1:

I don't have enough reputation for a comment, but since no one else is replying I try to give an answer. I don't remember about 2.7 but in Python 3 I normally use something like this:

os.system("xdg-open "+ <string>)

os.system is a command also in Python 2.7. You have to import os first. Hope it helps ;-)

Solution 2:

This works on Linux, it will open the requested file with the appropriate software.

Use code below:

import subprocess
subprocess.call(["xdg-open", "filename"])

Post a Comment for "Python Xdg-open()"