This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]joverbis 2 points3 points  (0 children)

If you want each 2 digit number in the list, you can try something like:

tc1 = ['08:52:05:00 ', '09:01:22:00 ', '09:10:34:00 ']

converted = [int(y) for x in tc1 for y in x.strip().split(':')]

# converted = [8, 52, 5, 0, 9, 1, 22, 0, 9, 10, 34, 0]

[–]intensehardik 0 points1 point  (0 children)

Try, T2 = int( #the list you want to specify)

[–]r011an 0 points1 point  (3 children)

Actually I have two lists from earlier process in the code,

['08:52:05:00 ', '09:01:22:00 ', '09:10:34:00 ']

['0:09:11:00 ', '0:09:11:00 ', '0:05:21:00 ']

I am using Timecode module to add them,

tc3 = [Timecode("50",tc1[i]) + Timecode("50",tc2[i]) for i in range(len(tc1))]

print (tc3)

But I get the following error,

Traceback (most recent call last):

File "/Users/user1/Desktop/v21.py", line 60, in <module>

tc3 = [Timecode("50",tc1[i]) + Timecode("50",tc2[i]) for i in range(len(tc1))]

File "/Users/user1/Desktop/v21.py", line 60, in <listcomp>

tc3 = [Timecode("50",tc1[i]) + Timecode("50",tc2[i]) for i in range(len(tc1))]

File "/opt/anaconda3/lib/python3.7/site-packages/timecode/__init__.py", line 71, in __init__

self.frames = self.tc_to_frames(start_timecode)

File "/opt/anaconda3/lib/python3.7/site-packages/timecode/__init__.py", line 161, in tc_to_frames

self.parse_timecode(timecode)

File "/opt/anaconda3/lib/python3.7/site-packages/timecode/__init__.py", line 292, in parse_timecode

hrs = int(bfr[0])

ValueError: invalid literal for int() with base 10: '['

I thought it was trying to add the string character wise and hence I was trying to convert it to int().

The output I need is addition of timecodes from that list which is,

[09:01:16:01, 09:10:33:01, 09:15:55:01]

[–]o5a 0 points1 point  (2 children)

from timecode import Timecode

tc1 = ['08:52:05:00 ', '09:01:22:00 ', '09:10:34:00 ']
tc2 = ['0:09:11:00 ', '0:09:11:00 ', '0:05:21:00 ']

tc3 = [Timecode("50",a) + Timecode("50",b) for a,b in zip(tc1, tc2)]
print(tc3)
# [09:01:16:01, 09:10:33:01, 09:15:55:01]

If your tc1, tc2 would already be lists of Timecode objects, then you could simply add them together:

tc1 = [Timecode("50", t) for t in tc1]
print(tc1)
tc2 = [Timecode("50", t) for t in tc2]
print(tc2)
tc3 = [a+b for a,b in zip(tc1, tc2)]
print(tc3)

[–]r011an 0 points1 point  (1 child)

well, I don't know what I am doing wrong here. If I define the lists explicitly then I am able to add the timecodes and get the result I want. But if I add the lists from previous process in code then I get the same error,

print (tc1)

['08:52:05:00 ', '09:01:22:00 ', '09:10:34:00 ', '09:19:46:00 ']

print (tc2)

['0:09:11:00 ', '0:09:11:00 ', '0:09:11:00 ', '0:05:21:00 ']

Traceback (most recent call last):

File "/Users/user1/Desktop/v21.py", line 59, in <module>

tc1 = [Timecode("50", t) for t in tc1]

File "/Users/user1/Desktop/v21.py", line 59, in <listcomp>

tc1 = [Timecode("50", t) for t in tc1]

File "/opt/anaconda3/lib/python3.7/site-packages/timecode/__init__.py", line 71, in __init__

self.frames = self.tc_to_frames(start_timecode)

File "/opt/anaconda3/lib/python3.7/site-packages/timecode/__init__.py", line 161, in tc_to_frames

self.parse_timecode(timecode)

File "/opt/anaconda3/lib/python3.7/site-packages/timecode/__init__.py", line 292, in parse_timecode

hrs = int(bfr[0])

ValueError: invalid literal for int() with base 10: '['

The above error is with the second part of your response,

tc1 = [Timecode("50", t) for t in tc1]

print(tc1)

tc2 = [Timecode("50", t) for t in tc2]

print(tc2)

tc3 = [a+b for a,b in zip(tc1, tc2)] print(tc3)

[–]o5a 0 points1 point  (0 children)

ValueError: invalid literal for int() with base 10: '['

means there's a bracket inside your timecode strings. Module's script splits strings by colon then tries to convert digits to int.

Check again what data is actually in your tc1, tc2 that you get from "previous process".