Python Forum
First line with digits before last line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First line with digits before last line
#6
Thank you guys!
I appreciate your help!
I'm really not that good with programming.
I came up with a simple (for me) solution that seems working fine.
I probably invented a bicycle... Wink

Here is the code:

import re
import linecache
 
fl = 'C:/01/last_line.txt'
with open(r"C:/01/last_line.txt") as mfiler:
    lnc = 0  # <-- Line Numners
    frt_ln = mfiler.readline()  # <------------------ First Line
    print(f" Fl -> {frt_ln}")
    
    for rn_l in mfiler:
        lnc+=1    
        if 'Start' in rn_l :
            continue        
            # do something with the lines
        la_line = rn_l
 
while (lnc) > 0 :
    print(f" Number of Ln in the File = {str(lnc)}") # < --- Number of lines in the file
    if re.search('^\d+', la_line) :
        print(f"  LN has DT --> {la_line} ")
        lnc = 0
        break
    else :
        lnc = lnc -1
        la_line = linecache.getline('C:/01/last_line.txt', lnc)
Thank you again!
I love this forum Big Grin
Reply


Messages In This Thread
RE: First line with digits before last line - by tester_V - Aug-22-2022, 09:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 249 May-23-2024, 03:02 PM
Last Post: deanhystad
  Line graph with two superimposed lines sawtooth500 4 435 Apr-02-2024, 08:56 PM
Last Post: sawtooth500
  How to add multi-line comment section? Winfried 1 271 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  break print_format lengthy line akbarza 4 469 Mar-13-2024, 08:35 AM
Last Post: akbarza
  Reading and storing a line of output from pexpect child eagerissac 1 4,386 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  coma separator is printed on a new line for some reason tester_V 4 598 Feb-02-2024, 06:06 PM
Last Post: tester_V
  problem with spliting line in print akbarza 3 478 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  Unable to understand the meaning of the line of code. jahuja73 0 368 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Receive Input on Same Line? johnywhy 8 868 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  Reading in of line not working? garynewport 2 923 Sep-19-2023, 02:22 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020