免费注册 查看新帖 |

Chinaunix

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

各位大哥看看,python参数传递问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-08 12:04 |只看该作者 |倒序浏览
请问我如何把参数传递给python的mysqldb,比如cgi页面中的参数或shell中的时间参数


#!/usr/bin/python
import MySQLdb
a=[]
db = MySQLdb.connect(user="xxx", db="xxx",passwd="xxx")


r = db.cursor()
r.execute("select test from test1 where dtGetTime>=参数 and dtGetTime<=参数")
for row in range(r.rowcount):
    rr = r.fetchone()
    for col in rr:
        a.append(col)
r.close()
db.close()

论坛徽章:
0
2 [报告]
发表于 2006-03-08 13:49 |只看该作者
试试
  1. r.execute("select test from test1 where dtGetTime>=%s and dtGetTime<=%s", (arg1, arg2))
复制代码

论坛徽章:
0
3 [报告]
发表于 2006-03-08 13:53 |只看该作者

回复 2楼 wolfg 的帖子

arg1,arg2怎么设置呢?

论坛徽章:
0
4 [报告]
发表于 2006-03-08 16:17 |只看该作者
原帖由 david123 于 2006-3-8 13:53 发表
arg1,arg2怎么设置呢?

看你的具体应用了
dtGetTime是个日期字段吗?试试把arg1和arg2设成两个formated的时间串

论坛徽章:
0
5 [报告]
发表于 2006-03-08 16:37 |只看该作者
原帖由 wolfg 于 2006-3-8 16:17 发表

看你的具体应用了
dtGetTime是个日期字段吗?试试把arg1和arg2设成两个formated的时间串


我的意思是怎么把参数传给arg1和arg2。dtGetTime是个日期字段。
刚刚试过了
我这样写
arg1=10
r.execute("select test from test1 where dtGetTime>=%s ", arg1)可以
但是怎么从外部把参数或者字符串传给arg1,比如php页面中有个框,在里面填上日期,按确定,python脚本就能接收这个参数,并执行。

论坛徽章:
0
6 [报告]
发表于 2006-03-09 09:46 |只看该作者
原帖由 david123 于 2006-3-8 16:37 发表
但是怎么从外部把参数或者字符串传给arg1,比如php页面中有个框,在里面填上日期,按确定,python脚本就能接收这个参数,并执行。

是想用python做cgi脚本吧
得使用cgi这个模块

  1. import cgi
  2. import cgitb; cgitb.enable()
  3. ......
  4. form = cgi.FieldStorage()
  5. if not (form.has_key("name") and form.has_key("addr")):
  6.     print "<H1>Error</H1>"
  7.     print "Please fill in the name and addr fields."
  8.     return
  9. print "<p>name:", form["name"].value
  10. print "<p>addr:", form["addr"].value
  11. ...further form processing here...
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP