I want to open .wav file in default program. But it doesn´t work. This is my code:

audiofile=(myFile[index]+".wav") # I have all files in array (without ".wav") 

try:
    try:
        os.system('xdg-open audiofile')
    except:
        os.system('start audiofile')                    
except:
    print "error"

I don´t get any error, but it doesn´t work. How can I solve it? Thank you.

没有正确的解决方案

其他提示

You aren't substituting the name of the audio file into your OS commands, so it can't possibly work.

You'd need something like:

os.system('xdg-open ' + audiofile)

This assumes that you have a default application associated with .wav files, which of course you can test by trying your command manually.

You might also want to check the return value of os.system for an error code, rather than relying on exceptions.

First of all, you should fill the variable audiofile into the command, not the string 'audiofile' itself

os.system('xdg-open %s' % audiofile)

Second, os.system will NOT throw an exception when xdg-open or start doesn't exist in system. Determine the type of system first by platform.system

>>> import platform
>>> platform.system()
'Linux'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top