Python csv.writer问题

时间:2019-04-25 19:10:59

标签: python-3.x csv writer

要跟踪密码更新脚本,我想编写连接日志,因此我将代码编写如下,只放置了一部分,还提供了套接字问题和成功连接的信息。< / p>

问题出现在文件csv中的返回级别,我到处都有逗号!

Here GitHub链接,我无法嵌入图像

pass_cisco_change.py

journal.csv

如何删除所有这些逗号?

1 个答案:

答案 0 :(得分:0)

代码

ip_address = sys.argv[1] 
username = sys.argv[2]
password = sys.argv[3]
new_pw = sys.argv[4]

ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy() )
try:
    ssh_client.connect(ip_address, 22, username, password, look_for_keys=False, allow_agent=False)
except paramiko.AuthenticationException:
    result = "Authentication failed"
    with open("journal.csv", "a") as suivi:
        csv_writer = csv.writer(suivi)
        csv_writer.writerows([ip_address,result])`    

结果:

1,9,2,.,1,6,8,.,0,.,1
A,u,t,h,e,n,t,i,c,a,t,i,o,n, ,f,a,i,l,e,d