前两天去面试web developer,面试官提出一个问题,用JavaScript或者Python实现字符串反转,我选择了Python,然后写出了代码(错误的): #!/usr/bin/env python #-*-coding:utf-8-*- __author__ = 'ZhangHe' def reverse(s): l = 0 r = len(s) - 1 while l < r: s[l],s[r] = s[r],s[l] l += 1 r -= 1 return s 然后面试官问了两
python在操作数据库执行sql的时候我们经常会遇到传参问题,以下是我总结的几种方法: 1.格式化字符串 city = 'beijing'cur.execute(“SELECT * FROM %s WHERE city = %s”, city) 2.使用字典传递 sql = “INSERT INTO user VALUES(%(username)s, %(password)s, %(email)s)”value = {“username”:zhangsan,“password”:123456,
1.Python连接mysql数据库,并且传递参数 con = MySQLdb.connect(host='***', user='root', passwd='***', db='***', port=***, charset='utf8')cur1 = con.cursor()cur2 = con.cursor()cur1.execute("SELECT distinct(a6) FROM b where a2=%s ", (Id[0]))cur2.execute("SE
最近由于项目自动化构建的需要,研究了下gradle调用脚本并传参的用法,在此作个总结. Pre build.gradle中定义了$jenkinsJobName $jenkinsBuild两个Jenkins变量,意图将gradle中的这两个值传到shell/python脚本中去用 def jenkinsBuild = System.getenv("BUILD_NUMBER") ?: "0" println "jenkinsBuild is set to $j