Python checking end of file before last iterationCompare File with ignore some line/last lineOptimize...

What is this diamond of every day?

Vocabulary for giving just numbers, not a full answer

Gaining more land

Dynamic Linkage of LocatorPane and InputField

Street obstacles in New Zealand

Is this Paypal Github SDK reference really a dangerous site?

Does "Until when" sound natural for native speakers?

MySQL importing CSV files really slow

Does Christianity allow for believing on someone else's behalf?

Is it possible to find 2014 distinct positive integers whose sum is divisible by each of them?

Are all players supposed to be able to see each others' character sheets?

Shifting between bemols and diesis in the key signature

Why restrict private health insurance?

Virginia employer terminated employee and wants signing bonus returned

When Schnorr signatures are part of Bitcoin will it be possible validate each block with only one signature validation?

Can't make sense of a paragraph from Lovecraft

After `ssh` without `-X` to a machine, is it possible to change `$DISPLAY` to make it work like `ssh -X`?

Getting the || sign while using Kurier

What do *foreign films* mean for an American?

What do you call someone who likes to pick fights?

Can we track matter through time by looking at different depths in space?

Why couldn't the separatists legally leave the Republic?

Finitely many repeated replacements

Why do we say ‘pairwise disjoint’, rather than ‘disjoint’?



Python checking end of file before last iteration


Compare File with ignore some line/last lineOptimize iteration output to text fileDead-end filling maze solver in PythonCross-platform file hash sum generator in PythonImproved version of “Let's read a random Goodreads book…”Python Batch File RenamerProduct iteration while checking for overlapsSelection sort with reduced comparison count: Python iteration 2Python file overwriting scriptSpeed up iteration for large dataset in python













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$

















    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$















      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 12 mins 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.






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          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: "196"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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
          });


          }
          });






          mKalita is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215157%2fpython-checking-end-of-file-before-last-iteration%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








          mKalita is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          mKalita is a new contributor. Be nice, and check out our Code of Conduct.













          mKalita is a new contributor. Be nice, and check out our Code of Conduct.












          mKalita is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • 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.


          Use MathJax to format equations. MathJax reference.


          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%2fcodereview.stackexchange.com%2fquestions%2f215157%2fpython-checking-end-of-file-before-last-iteration%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







          Popular posts from this blog

          Fairchild Swearingen Metro Inhaltsverzeichnis Geschichte | Innenausstattung | Nutzung | Zwischenfälle...

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...

          Marineschifffahrtleitung Inhaltsverzeichnis Geschichte | Heutige Organisation der NATO | Nationale und...