subprocess.Popen with a unicode path

前端 未结 4 1668
面向向阳花
面向向阳花 2020-12-10 07:01

I have a unicode filename that I would like to open. The following code:

cmd = u\'cmd /c \"C:\\\\Pok\\xe9mon.mp3\"\'
cmd = cmd.encode(\'utf-8\')
subprocess.P         


        
4条回答
  •  粉色の甜心
    2020-12-10 07:31

    Your problem can be solved through smart_str function of Django module.

    Use this code:

    from django.utils.encoding import smart_str, smart_unicode
    cmd = u'cmd /c "C:\\Pok\xe9mon.mp3"'
    smart_cmd = smart_str(cmd)
    subprocess.Popen(smart_cmd)
    

    You can find information on how to install Django on Windows here. You can first install pip and then you can install Django by starting a command shell with administrator privileges and run this command:

    pip install Django
    

    This will install Django in your Python installation's site-packages directory.

提交回复
热议问题