开发者

python + Semicolon written to file is written on the next line

开发者 https://www.devze.com 2023-01-11 11:54 出处:网络
I have this simple python expression: fscript.write ((\"update %s va set %s = %s where %s = %s;\") % (argv[1],argv[2],vl[0],argv[3],vl[1]))

I have this simple python expression:

fscript.write (("update %s va set %s = %s where %s = %s;") % (argv[1],argv[2],vl[0],argv[3],vl[1]))

And I would expect to receive output like this

update some_table va set active_id = 1 where id = 5;
update some_table va set active_id = 1 where id = 3;
...more 开发者_如何学Pythonlines...

However, i'm getting this

update some_table va set active_id = 1 where id = 5
;update some_table va set active_id = 1 where id = 3
...more lines....

Anything i'm missing ?

Thanks in advance


I would try adding a strip() to your latest parameter that could end with \n.

fscript.write (("update %s va set %s = %s where %s = %s;") % (argv[1],argv[2],vl[0],argv[3],vl[1].strip()))


Some value of vl[1] is a string with a newline in it, not an integer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号