在第一个字段中需要数据的行

时间:2016-03-23 16:43:58

标签: python rows

遇到第[3行]要求第一行的csv中的数据或者它会引发错误的问题。

此字段用于说明/评论,因此可选。

对于什么必须是引号或其他任何东西的丑陋代码的任何建议都会很棒。从各个网站一起黑客攻击。

感谢您抽出时间和信息。

print "#######  CSV FORMAT REQUIREMENTS ##########" '\n',
print "     File should be in the same directory as this script" '\n',
print "     First column needs to be device or network name" '\n',
print "     Second column needs to be IP address" '\n',
print "     Third column should be mask in CIDR starting with a slash (/32)" '\n',
print "     Forth column for any comments, can be blank" '\n',
print "     See IPSample.csv file for example format" '\n',
print "name of csv file? (In same directory as this script)",
infile = raw_input()
print "" '\n',
print "####### Your Output file" '\n',
print "Output file can be any name, should end it with .txt" '\n',
print "name of output text file? (Will be saved in same directory as this script)",
outfile = raw_input()

import csv

f = open(infile, 'r')
e = "edit "
s = "set subnet "
com = "set comment "
qq = '"'
dash ='-'
n = "next"
csv_f = csv.reader(f)
import sys
sys.stdout=open(outfile,"w")
print "##### Double Check output for errors" '\n',
print "##### Its best to copy/paste this in small batches in case of any errors" '\n',
print "##### Comments with empty quotes will be ignored for FortiGate" '\n',
print "configure firewall address" '\n',
for row in csv_f:  #for always end in a colon
    print e + str(row[0]+dash+row[1]+row[2])                #creates object name
    print s + str(row[1]+row[2])            #Creates object host or subnet
    print com + qq + str(row[3])+qq     #Creates comment
    print n                             #inserts 'next' command

f.close()

1 个答案:

答案 0 :(得分:0)

如果您知道每行总是至少有3列,请检查行的长度。你的for循环看起来像:

date >= now() - INTERVAL 3 second;