需要第一个字段中的数据的行
Row requiring data in first field
运行 遇到问题,其中行 [3] 需要 csv 中第一行的数据,否则会引发错误。
此字段用于 description/comments,因此它是可选的。
此外,任何关于引号的丑陋代码或其他任何内容的建议都会很棒。从各个网站一起破解这个。
感谢您的时间和信息。
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()
如果您知道每行总是至少有 3 列,请检查行的长度。你的 for 循环看起来像:
for row in csv_f:
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
if len(row) == 4:
print com + qq + str(row[3])+qq #Creates comment
print n #inserts 'next' command
运行 遇到问题,其中行 [3] 需要 csv 中第一行的数据,否则会引发错误。
此字段用于 description/comments,因此它是可选的。
此外,任何关于引号的丑陋代码或其他任何内容的建议都会很棒。从各个网站一起破解这个。
感谢您的时间和信息。
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()
如果您知道每行总是至少有 3 列,请检查行的长度。你的 for 循环看起来像:
for row in csv_f:
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
if len(row) == 4:
print com + qq + str(row[3])+qq #Creates comment
print n #inserts 'next' command