CSV parsing error with particular row[8]: list index out of range












0














I am trying to fetch row values from CSV files, everything works as expected except row[8]. But same row works as row[7] if I delete any other row before it.



comment = row[8]
IndexError: list index out of range


Here is the sample CSV:



190,3391d5ae,,Host-1,FuelNode-1,"http,tcp-8000",False,,created on - 6/10/14
192,25dbbf4c,sam,"vlan85,vlan86","Srv1,Srv2",dhcp-relay,False,25-10-2018,



Please note there are few fields do not have values present or blank.




Here is the code i have written.



outFiles = os.listdir('datastore/csv_out_files')
ext = "*.csv"
for csvoutfile in outFiles:
if fnmatch.fnmatch(csvoutfile, ext):
with open('datastore/csv_out_files/'+ csvoutfile) as f:
rows = csv.reader(f, delimiter=',')
headers = next(rows)
for row in rows:
uid = row[1]
name = row[2]
source = row[3]
destination = row[4]
service = row[5]
enabled = row[6]
use_date = row[7]
comment = row[8]

if not use_date:
use_date = "Never Used"

print " UID:", (uid)
print " Name:", (name)
print " Source:", (source)
print " Destination:", (destination)
print " Service:", (service)
print " Enabled:", (enabled)
print " Last Used:", (use_date)
print " Additional Info:", (comment)


Please help me, I am not able to figure this out.










share|improve this question






















  • Working as intended for me in Python3.6
    – Strinnityk
    Nov 20 '18 at 10:45










  • Yes it should work but getting above error. i am using python 2.7.5. Dont know whats wrong.
    – Sam
    Nov 20 '18 at 10:46












  • I've just tried it in Python 2.7.15 and it's working for me. I'll try to test it in 2.7.5.
    – Strinnityk
    Nov 20 '18 at 10:53
















0














I am trying to fetch row values from CSV files, everything works as expected except row[8]. But same row works as row[7] if I delete any other row before it.



comment = row[8]
IndexError: list index out of range


Here is the sample CSV:



190,3391d5ae,,Host-1,FuelNode-1,"http,tcp-8000",False,,created on - 6/10/14
192,25dbbf4c,sam,"vlan85,vlan86","Srv1,Srv2",dhcp-relay,False,25-10-2018,



Please note there are few fields do not have values present or blank.




Here is the code i have written.



outFiles = os.listdir('datastore/csv_out_files')
ext = "*.csv"
for csvoutfile in outFiles:
if fnmatch.fnmatch(csvoutfile, ext):
with open('datastore/csv_out_files/'+ csvoutfile) as f:
rows = csv.reader(f, delimiter=',')
headers = next(rows)
for row in rows:
uid = row[1]
name = row[2]
source = row[3]
destination = row[4]
service = row[5]
enabled = row[6]
use_date = row[7]
comment = row[8]

if not use_date:
use_date = "Never Used"

print " UID:", (uid)
print " Name:", (name)
print " Source:", (source)
print " Destination:", (destination)
print " Service:", (service)
print " Enabled:", (enabled)
print " Last Used:", (use_date)
print " Additional Info:", (comment)


Please help me, I am not able to figure this out.










share|improve this question






















  • Working as intended for me in Python3.6
    – Strinnityk
    Nov 20 '18 at 10:45










  • Yes it should work but getting above error. i am using python 2.7.5. Dont know whats wrong.
    – Sam
    Nov 20 '18 at 10:46












  • I've just tried it in Python 2.7.15 and it's working for me. I'll try to test it in 2.7.5.
    – Strinnityk
    Nov 20 '18 at 10:53














0












0








0







I am trying to fetch row values from CSV files, everything works as expected except row[8]. But same row works as row[7] if I delete any other row before it.



comment = row[8]
IndexError: list index out of range


Here is the sample CSV:



190,3391d5ae,,Host-1,FuelNode-1,"http,tcp-8000",False,,created on - 6/10/14
192,25dbbf4c,sam,"vlan85,vlan86","Srv1,Srv2",dhcp-relay,False,25-10-2018,



Please note there are few fields do not have values present or blank.




Here is the code i have written.



outFiles = os.listdir('datastore/csv_out_files')
ext = "*.csv"
for csvoutfile in outFiles:
if fnmatch.fnmatch(csvoutfile, ext):
with open('datastore/csv_out_files/'+ csvoutfile) as f:
rows = csv.reader(f, delimiter=',')
headers = next(rows)
for row in rows:
uid = row[1]
name = row[2]
source = row[3]
destination = row[4]
service = row[5]
enabled = row[6]
use_date = row[7]
comment = row[8]

if not use_date:
use_date = "Never Used"

print " UID:", (uid)
print " Name:", (name)
print " Source:", (source)
print " Destination:", (destination)
print " Service:", (service)
print " Enabled:", (enabled)
print " Last Used:", (use_date)
print " Additional Info:", (comment)


Please help me, I am not able to figure this out.










share|improve this question













I am trying to fetch row values from CSV files, everything works as expected except row[8]. But same row works as row[7] if I delete any other row before it.



comment = row[8]
IndexError: list index out of range


Here is the sample CSV:



190,3391d5ae,,Host-1,FuelNode-1,"http,tcp-8000",False,,created on - 6/10/14
192,25dbbf4c,sam,"vlan85,vlan86","Srv1,Srv2",dhcp-relay,False,25-10-2018,



Please note there are few fields do not have values present or blank.




Here is the code i have written.



outFiles = os.listdir('datastore/csv_out_files')
ext = "*.csv"
for csvoutfile in outFiles:
if fnmatch.fnmatch(csvoutfile, ext):
with open('datastore/csv_out_files/'+ csvoutfile) as f:
rows = csv.reader(f, delimiter=',')
headers = next(rows)
for row in rows:
uid = row[1]
name = row[2]
source = row[3]
destination = row[4]
service = row[5]
enabled = row[6]
use_date = row[7]
comment = row[8]

if not use_date:
use_date = "Never Used"

print " UID:", (uid)
print " Name:", (name)
print " Source:", (source)
print " Destination:", (destination)
print " Service:", (service)
print " Enabled:", (enabled)
print " Last Used:", (use_date)
print " Additional Info:", (comment)


Please help me, I am not able to figure this out.







python python-2.7 csv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 10:40









Sam

388




388












  • Working as intended for me in Python3.6
    – Strinnityk
    Nov 20 '18 at 10:45










  • Yes it should work but getting above error. i am using python 2.7.5. Dont know whats wrong.
    – Sam
    Nov 20 '18 at 10:46












  • I've just tried it in Python 2.7.15 and it's working for me. I'll try to test it in 2.7.5.
    – Strinnityk
    Nov 20 '18 at 10:53


















  • Working as intended for me in Python3.6
    – Strinnityk
    Nov 20 '18 at 10:45










  • Yes it should work but getting above error. i am using python 2.7.5. Dont know whats wrong.
    – Sam
    Nov 20 '18 at 10:46












  • I've just tried it in Python 2.7.15 and it's working for me. I'll try to test it in 2.7.5.
    – Strinnityk
    Nov 20 '18 at 10:53
















Working as intended for me in Python3.6
– Strinnityk
Nov 20 '18 at 10:45




Working as intended for me in Python3.6
– Strinnityk
Nov 20 '18 at 10:45












Yes it should work but getting above error. i am using python 2.7.5. Dont know whats wrong.
– Sam
Nov 20 '18 at 10:46






Yes it should work but getting above error. i am using python 2.7.5. Dont know whats wrong.
– Sam
Nov 20 '18 at 10:46














I've just tried it in Python 2.7.15 and it's working for me. I'll try to test it in 2.7.5.
– Strinnityk
Nov 20 '18 at 10:53




I've just tried it in Python 2.7.15 and it's working for me. I'll try to test it in 2.7.5.
– Strinnityk
Nov 20 '18 at 10:53












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391197%2fcsv-parsing-error-with-particular-row8-list-index-out-of-range%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391197%2fcsv-parsing-error-with-particular-row8-list-index-out-of-range%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown