-1

I'm a beginner at Python trying to write my first script. I've got a text file with multiple lines and need to eventually extract a piece of timecode from the list. The list looks like this:

010  AX       V     C        01:01:26:10 01:01:27:17 01:00:08:19 01:00:10:02
* FROM CLIP NAME: movie1.mov

011  AX       V     C        01:01:30:19 01:01:32:19 01:00:10:02 01:00:12:02
* FROM CLIP NAME: movie2.mov

012  AX       V     C        01:00:15:01 01:00:17:13 01:00:12:02 01:00:14:14
* FROM CLIP NAME: movie3.mov

etc.

My first objective is to grab the first timecode displayed.

I know that the first timecode on every line starts at character #29 and ends at character #40 so I started by trying to remove the first 29 characters but anytime it prints it's not starting at the right character.

timecode = []                               # Declaring my empty list.
with open ('test.edl', 'rt') as myfile:     # Opening the edl.
    for myline in myfile:                   # For each line in the file,
        print(myline.lstrip(myline[:29]))   # strip first 29 chars

Rather than stripping the first 29 chars, I'm receiving this in return:

:01:26:10 01:01:27:17 01:00:08:19 01:00:10:02

movie1.mov


:01:30:19 01:01:32:19 01:00:10:02 01:00:12:02

movie2.mov


:00:15:01 01:00:17:13 01:00:12:02 01:00:14:14

movie3.mov

Even when I change print(myline.lstrip(myline[:29])) to [:25], it prints the lines the same way.

When I'm using [:20] it's giving me a better result but it's still incorrect.

C 01:00:15:01 01:00:17:13 01:00:12:02 01:00:14:14

I've been searching relentlessly to figure out what I'm doing wrong here but no luck.. Again, complete beginner here so I'm sorry if this is plain stupidity.

Thank you very much!

Erwin
  • 13
  • 5

2 Answers2

3

lstrip does not do what you expect it to. myline.lstrip(myline[:29]) will remove characters from the left of myline as long as they are found anywhere in myline[:29], i.e. the first 29 characters of myline. Therefore you are certainly removing the first 29 characters, but also 01 at the beginning of the of the time code, because 0 and 1 appear in the first 29 characters of myline. (The 0 is removed anyway, because you miscalculated the bound, myline[:29] would include the 29th character).

You can select all characters, starting from the 29th character with myline[29:].

walnut
  • 21,629
  • 4
  • 23
  • 59
1

you want to start at 29, not end at 29. also, lstrip() will take off more. try replacing your 4th line with this:

print(myline[29:])
David Culbreth
  • 2,610
  • 16
  • 26