Python checking end of file before last iteration [on hold]












0












$begingroup$


i have this loop processing a csv i get to the last line and i get an error because it tries to read empty line and kills program how would i check here for that ?



while True:
if in_file.closed: break
lines = line.strip()
if len(lines) > 0:
print (line ,"line1")
src_ip, src_port, dst_ip, dst_port, msg = lines.split(',')
src = '{}:{}'.format(src_ip, src_port)
dst = '{}:{}'.format(dst_ip, dst_port)
if in_file is None:
break

else:
line2 =next(in_file)
print(line2)
lines2 = line2.strip()


the point where it stops is on the line2 =next(in_file)
i get this error from my run ------
Traceback (most recent call last):
File "C:Usersmattseclipse-workspacemy_projectsrcpostprocesspost_process.py", line 74, in
line2 =next(in_file)
StopIteration



new to python so any help appreciated Thanks










share|improve this question







New contributor




mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by l0b0, Austin Hastings, Vogel612 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – l0b0, Austin Hastings, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    $endgroup$
    – Vogel612
    1 hour ago
















0












$begingroup$


i have this loop processing a csv i get to the last line and i get an error because it tries to read empty line and kills program how would i check here for that ?



while True:
if in_file.closed: break
lines = line.strip()
if len(lines) > 0:
print (line ,"line1")
src_ip, src_port, dst_ip, dst_port, msg = lines.split(',')
src = '{}:{}'.format(src_ip, src_port)
dst = '{}:{}'.format(dst_ip, dst_port)
if in_file is None:
break

else:
line2 =next(in_file)
print(line2)
lines2 = line2.strip()


the point where it stops is on the line2 =next(in_file)
i get this error from my run ------
Traceback (most recent call last):
File "C:Usersmattseclipse-workspacemy_projectsrcpostprocesspost_process.py", line 74, in
line2 =next(in_file)
StopIteration



new to python so any help appreciated Thanks










share|improve this question







New contributor




mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by l0b0, Austin Hastings, Vogel612 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – l0b0, Austin Hastings, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    $endgroup$
    – Vogel612
    1 hour ago














0












0








0





$begingroup$


i have this loop processing a csv i get to the last line and i get an error because it tries to read empty line and kills program how would i check here for that ?



while True:
if in_file.closed: break
lines = line.strip()
if len(lines) > 0:
print (line ,"line1")
src_ip, src_port, dst_ip, dst_port, msg = lines.split(',')
src = '{}:{}'.format(src_ip, src_port)
dst = '{}:{}'.format(dst_ip, dst_port)
if in_file is None:
break

else:
line2 =next(in_file)
print(line2)
lines2 = line2.strip()


the point where it stops is on the line2 =next(in_file)
i get this error from my run ------
Traceback (most recent call last):
File "C:Usersmattseclipse-workspacemy_projectsrcpostprocesspost_process.py", line 74, in
line2 =next(in_file)
StopIteration



new to python so any help appreciated Thanks










share|improve this question







New contributor




mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




i have this loop processing a csv i get to the last line and i get an error because it tries to read empty line and kills program how would i check here for that ?



while True:
if in_file.closed: break
lines = line.strip()
if len(lines) > 0:
print (line ,"line1")
src_ip, src_port, dst_ip, dst_port, msg = lines.split(',')
src = '{}:{}'.format(src_ip, src_port)
dst = '{}:{}'.format(dst_ip, dst_port)
if in_file is None:
break

else:
line2 =next(in_file)
print(line2)
lines2 = line2.strip()


the point where it stops is on the line2 =next(in_file)
i get this error from my run ------
Traceback (most recent call last):
File "C:Usersmattseclipse-workspacemy_projectsrcpostprocesspost_process.py", line 74, in
line2 =next(in_file)
StopIteration



new to python so any help appreciated Thanks







python






share|improve this question







New contributor




mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









mKalitamKalita

1




1




New contributor




mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






mKalita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by l0b0, Austin Hastings, Vogel612 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – l0b0, Austin Hastings, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.







put on hold as off-topic by l0b0, Austin Hastings, Vogel612 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – l0b0, Austin Hastings, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.












  • $begingroup$
    Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    $endgroup$
    – Vogel612
    1 hour ago


















  • $begingroup$
    Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    $endgroup$
    – Vogel612
    1 hour ago
















$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612
1 hour ago




$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612
1 hour ago










0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?