我需要在布尔变量设置为时才打印一些东西True
.所以,看后这个,我试图用一个简单的例子:
>>> a = 100
>>> b = True
>>> print a if b
File "<stdin>", line 1
print a if b
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
如果我写的话也一样print a if b==True
.
我在这里错过了什么?
简单的初学者问题:
我已经创建了一个小的python脚本来切换我用于测试的两个文件.
我的问题是,对于以下代码,什么是一个好的python格式样式:
import filecmp
import shutil
local = "local.txt"
remote = "remote.txt"
config_file = "C:\some\path\file.txt"
shutil.copyfile( remote if( filecmp.cmp(local, config_file ) ) else local, config_file )
Run Code Online (Sandbox Code Playgroud)
要么
shutil.copyfile( remote
if( filecmp.cmp(local, config_file ) )
else local,
config_file )
Run Code Online (Sandbox Code Playgroud)
要么
tocopy = remote if( filecmp.cmp( local, config_file ) ) else local
shutil.copyfile( tocopy, config_file )
Run Code Online (Sandbox Code Playgroud)
或者是什么?
另外,对于多字名称在python中命名var的优先方法是什么,是"to_copy","tocopy","toCopy","ToCopy"
谢谢.