Python checking end of file before last iteration [on hold]
$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
python
New contributor
$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.
add a comment |
$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
python
New contributor
$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
add a comment |
$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
python
New contributor
$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
python
New contributor
New contributor
New contributor
asked 2 hours ago
mKalitamKalita
1
1
New contributor
New contributor
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
add a comment |
$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
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
$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