最近在写python3的项目,在实际中运用到了根据 if 判断变量variable ,然后去拼接where子句。但是在百度、BING搜索中未找到合适的答案,这是自己想出来的典型php写法,这里做一下记录。不知道在python中如何做,如有python大神知道,请指点一下。

def getRooms( excludeId = None , limit = None ):
sql = 'SELECT * from computer_room WHERE 1=1 '
param = []
if excludeId :
sql += 'AND id <> %s '
param += [excludeId]
sql += 'ORDER BY weights ASC , id DESC '
if limit :
sql += 'LIMIT %s '
param += [limit]
config.cursor.execute( sql , param )
return config.cursor.fetchall()

  

最新文章

  1. 【Learning Python】【第三章】表、元组、字典和集合
  2. eclipse svn插件地址
  3. 一个好用的C#类型转换器
  4. oracle个人总结
  5. hdu 4970 Killing Monsters (思维 暴力)
  6. poj 2451 Uyuw&#39;s Concert(半平面交)
  7. Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 数据库版本控制器 完全破解+使用教程
  8. 第三篇——第二部分——第三文 配置SQL Server镜像——域环境
  9. MySQL大量数据入库的性能比较
  10. python-面向对象-01_面向对象(OOP)基本概念
  11. 论文阅读-使用隐马模型进行NER
  12. 读DataSnap源代码(三)
  13. MySQL 之迁移用户及权限
  14. RegExp,实现匹配合法时间(24小时制)的正则表达式
  15. Linux学习笔记01—安装LInux系统
  16. [Asp.net mvc]Html.ValidationSummary(bool)
  17. received shard failed for shard id
  18. JS 中的布尔运算符 &amp;&amp; 和 ||
  19. Scrapy:运行爬虫程序的方式
  20. [转]NMON服务器监控、指标说明

热门文章

  1. [LeetCode] 892. Surface Area of 3D Shapes 三维物体的表面积
  2. oracle--drop user 和 drop user cascade 的区别【转载】
  3. 代码移植的福音 namespace_alias
  4. [翻译 EF Core in Action 2.4] 加载相关数据
  5. 查看window重启日志
  6. java中的7个位运算运算符
  7. 基于FlexBox的无约束自适应
  8. NIO ByteBuffer的allocate与allocateDirect区别(HeapByteBuffer与DirectByteBuffer的区别)
  9. &lt;compilation debug=&quot;true&quot; targetFramework=&quot;4.5.2&quot;&gt; 报错解决方案
  10. 简单地判断判断两矩形相交/重叠 C#