我正在生成传递给python -c
的命令,如下所示
'python -c "import '+impMod+'; help('+module+'.'+method+') if \''+method+'\' in dir('+module+') else from '+impMod+' import '+method+' help('+method+')"'
得到如下输出:
python -c "import os; help(os.path.pathconf) if 'pathconf' in dir(os.path) else from os import pathconf help(pathconf)"
即使我尝试
python -c "import os; help(os.path.pathconf) if 'pathconf' in dir(os.path) else from os import pathconf; help(pathconf)"
但我不知道为什么会出现语法错误:无效语法
任何帮助都将不胜感激, 当做。你知道吗
你把陈述和表达搞混了。
from .. import ..
语法是一个语句,不能出现在表达式中,但您在... if ... else ...
表达式中使用它。此外,可以在shell字符串中使用换行符。你知道吗要在Python中实现这一点,您可能需要使用三重引号。你知道吗
相关问题 更多 >
编程相关推荐