我有一个方法,按顺序调用其他4个方法来检查特定的条件,并在每次返回Truthy时立即返回(不检查以下的方法).
def check_all_conditions():
x = check_size()
if x:
return x
x = check_color()
if x:
return x
x = check_tone()
if x:
return x
x = check_flavor()
if x:
return x
return None
Run Code Online (Sandbox Code Playgroud)
这似乎是很多行李代码.而不是每个2行if语句,我宁愿做类似的事情:
x and return x
Run Code Online (Sandbox Code Playgroud)
但那是无效的Python.我在这里错过了一个简单优雅的解决方案吗?顺便说一下,在这种情况下,这四种检查方法可能很昂贵,所以我不想多次调用它们.
我正在 MacOS BigSur 上使用 pyinstaller 构建游戏。它构建正确,但失败并出现“libpython3.9.dylib”“找不到图像”错误(下面是完整错误)
pyinstaller 构建应用程序后,我运行它:dist/gralli_quest.app/Contents/MacOS/gralli_quest
这是启用调试后的输出:
[22699] PyInstaller Bootloader 3.x
[22699] LOADER: executable is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
[22699] LOADER: homepath is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS
[22699] LOADER: _MEIPASS2 is NULL
[22699] LOADER: archivename is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
[22699] LOADER: Cookie found at offset 0x17CD99D2
[22699] LOADER: Extracting binaries
[22699] LOADER: Executing self as child
[22699] LOADER: set _MEIPASS2 to /var/folders/m7/322j4l357l3chdczl5j75phw0000gn/T/_MEIlAeO5C
[22699] LOADER: Registering signal handlers
[22704] PyInstaller Bootloader 3.x
[22704] LOADER: executable is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS/gralli_quest
[22704] LOADER: homepath is /Users/bernard/projects/gralli_quest/dist/gralli_quest.app/Contents/MacOS
[22704] LOADER: _MEIPASS2 is …Run Code Online (Sandbox Code Playgroud)