简体   繁体   中英

Can't open filepath in Python if filepath contains "," or "="

I can't open paths and highlight files if the path contains either "," or "=" (and maybe other symbols).

This code works if the path doesn't have the characters mentioned above:

import subprocess
subprocess.Popen(r'explorer /select,' + str(Path(link)))

I don't get any error it just defaults to open "This PC".

Does anyone out there know what's wrong?

You can use multiple arguments with check_call instead. Python will escape them correctly:

from subprocess import check_call
check_call(['explorer', '/select,', str(Path(link))])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM