codecamp

Flask 表达式和语句

常规空格规则:
  • 不对一元运算符使用空格(例如 -~ 等等),对圆括号同理
  • 在二元运算符间使用空格

Good

exp = -1.05
value = (item_value / item_count) * offset / exp
value = my_list[index]
value = my_dict['key']

Bad

exp = - 1.05
value = ( item_value / item_count ) * offset / exp
value = (item_value/item_count)*offset/exp
value=( item_value/item_count ) * offset/exp
value = my_list[ index ]
value = my_dict ['key']
禁止使用 Yoda 语句:

永远不要用变量与常量做比较,而是把常量与变量做比较:

God

if method == 'md5':
    pass

Bad

if 'md5' == method:
    pass
比较:
  • 跟任意类型: ==!=
  • 跟单例,使用 isis not (例如 foo is not None
  • 永远不要与 TrueFalse 做比较(比如永远不要写 foo == False ,而使用 not foo
否定包含检查:
使用 foo not in bar 而不是 not foo in bar
实例检查:
isinstance(a, C) 而不是 type(A) is C , 但通常试图避免 实例检查,请对特性检查。
Flask 总体布局
Flask 命名约定
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Flask 调试应用错误

Flask Python 3 支持

Flask 术语表

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }