python + 写入文件的分号写在下一行

标签 python python-3.x

我有这个简单的Python表达式:

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

我希望收到这样的输出

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

但是,我明白了

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

我缺少什么吗?

提前致谢

最佳答案

我会尝试将 strip() 添加到您最新的参数中,该参数可能以 \n 结尾。

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

关于python + 写入文件的分号写在下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3449358/

相关文章:

python - 如何用一个 for 循环而不是 if 条件来求和偶数和奇数?

python - 如何在 python 中使用正则表达式 'skip' 特定单词?

python - 如何在特定字符之外的指定位置拆分重复字符串?

python - 将代理图例句柄添加到现有图例

Python 2.7 和 OpenCV 使用 64 位和 32 位的不同结果,可能的错误?

Python - 通过同时串联合并两个列表

python - 使用 cx_Freeze(包括 PyQt5)创建 exe 时出现 ValueError

python - Gunicorn 工作线程在请求​​后不会压缩内存

python - 您如何将句点后的第一个单词和每个单词大写?

python 为什么 max(max(float_2d_array)) 给出错误的答案?