你如何在"python 2.7"中使用"os.path.isfile()"和一组"路径"但是一个变量文件名?

use*_*819 3 python path syntax-error python-2.7 os.path

我正在研究一个计算器程序作为一个更大的项目的一部分,当我终于认为我完成它时,我测试了定义的"退出"命令.然而,它失败了,经过一些研究,我来到这里.我需要知道的是如何使(path)参数具有一组预定义的路径,但也有一个实际文件名的变量.例如:/ HDD/APPS /(此处插入变量).

这是错误和发生错误的行:

   File "../../C.py", line 19
        if ( not os.path.isfile('/HDD/APPS/'exe)):
                                              ^
    SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

fal*_*tru 5

连接两个字符串:

>>> exe = 'exefile'
>>> '/HDD/APPS/' + exe
'/HDD/APPS/exefile'
Run Code Online (Sandbox Code Playgroud)

更优选地,使用os.path.join:

>>> import os
>>> os.path.join('/HDD/APPS/', exe)
'/HDD/APPS/exefile'
Run Code Online (Sandbox Code Playgroud)