2010-08-10 133 views
1

我有這個簡單的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.... 

任何我失蹤?

在此先感謝

回答

1

我會嘗試加入strip()到可能與\n結束您的最新參數。

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

不錯,沒想到那個。 – Tom 2010-08-10 13:24:38

1

vl[1]的某些值是一個帶有換行符的字符串,不是整數。