免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2607 | 回复: 4
打印 上一主题 下一主题

关于’的打印问题 [复制链接]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2016-02-06 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-02-26 15:52 |只看该作者 |倒序浏览
   写了一个python 程序 其中一个需求是删除数据库数据

  我写的程序代码 大致如下

  print '''  delete from table where a=%s ''' %test

  这句话打印的结果是
  delete from table where a= test

  而我需要的语句是

  delete from table where a= 'test'

  该如何实现呢.

论坛徽章:
0
2 [报告]
发表于 2014-02-26 16:32 |只看该作者
本帖最后由 nmweizi 于 2014-02-26 16:52 编辑

print """ delete '%s' """ % 'test'
不过这个样有安全漏洞。
这样好点。
execute('select * from tables where a=%s',('test',))

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
3 [报告]
发表于 2014-02-26 17:41 |只看该作者
print '''  delete from table where a='%s'  ''' % 'test'
print  " delete from table where a='%s'  "  % 'test'
print ' delete from table where a=\'%s\'  ' % 'test'
都可以吧!

论坛徽章:
1
子鼠
日期:2014-05-04 13:59:31
4 [报告]
发表于 2014-02-27 10:12 |只看该作者
  1. >>> name = 'poker'
  2. >>> print 'hello %r ' % name
  3. hello 'poker'
复制代码

论坛徽章:
0
5 [报告]
发表于 2014-02-28 14:15 |只看该作者
修杰_JIANG 发表于 2014-02-27 10:12

这个不错!
'r'     String (converts any Python object using repr()).
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP