how to convert timecode into seconds:fractions_of_a_second? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Given timecode in this format
00:00:00,0
What is the best way to convert this into seconds.fractions_of_a_second?

Here's a link for some python code to handle SMPTE timecodes http://code.google.com/p/pytimecode/
Hope it helps...

The datetime module is your friend in this case
import datetime
time_string = "17:48:12,98"
t = datetime.datetime.strptime(time_string, "%H:%M:%S,%f")
seconds = 60 * t.minute * t.hour
print (seconds, t.microsecond)

Related

Convert Timestamp(Nanoseconds format) to datetime [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I have a timestamp with Nanoseconds format that I want convert this to datetime in but I get error
import datetime
example_timestamp= '1629617204525776950'
example_timestamp= int(example_timestamp)
timestamp_to_date_time = datetime.datetime.fromtimestamp(example_timestamp).strftime('%Y-%m-%d %H:%M:%S,%f')
You should be using = to assign values and not :
You can do like this.
import datetime
example_timestamp = int('1629617204525776950')
timestamp_to_date_time = datetime.datetime.fromtimestamp(example_timestamp/1000000000).strftime('%Y-%m-%d %H:%M:%S,%f')
print(timestamp_to_date_time)
2021-08-22 07:26:44,525777

JSONArray into 2d numpy array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a json array in this format in PYTHON. How to make it to a 2d numpy array?
[{"z":1,"y":0.10000000149011612,"x":0.10000000149011612},{"z":0.6666666865348816,"y":0.10000000149011612,"x":0.20000000298023224},{"z":0.5,"y":0.10000000149011612,"x":0.30000001192092896},{"z":0.6666666865348816,"y":0.10000000149011612,"x":0.4000000059604645},{"z":0.3333333432674408,"y":0.10000000149011612,"x":0.5},{"z":0.1666666716337204,"y":0.10000000149011612,"x":0.6000000238418579},{"z":0.8333333134651184,"y":0.10000000149011612,"x":0.699999988079071},{"z":0.5,"y":0.10000000149011612,"x":0.800000011920929},{"z":0.5,"y":0.25999999046325684,"x":0.10000000149011612},{"z":0.5,"y":0.25999999046325684,"x":0.20000000298023224},{"z":1,"y":0.25999999046325684,"x":0.30000001192092896},{"z":0.1666666716337204,"y":0.25999999046325684,"x":0.4000000059604645},{"z":0.1666666716337204,"y":0.25999999046325684,"x":0.5},{"z":0.5,"y":0.25999999046325684,"x":0.6000000238418579},{"z":0.8333333134651184,"y":0.25999999046325684,"x":0.699999988079071},{"z":0.6666666865348816,"y":0.25999999046325684,"x":0.800000011920929},{"z":0.5,"y":0.41999998688697815,"x":0.10000000149011612},{"z":0.6666666865348816,"y":0.41999998688697815,"x":0.20000000298023224},{"z":0.1666666716337204,"y":0.41999998688697815,"x":0.30000001192092896},{"z":0.6666666865348816,"y":0.41999998688697815,"x":0.4000000059604645},{"z":0.5,"y":0.41999998688697815,"x":0.5},{"z":0.8333333134651184,"y":0.41999998688697815,"x":0.6000000238418579},{"z":0.8333333134651184,"y":0.41999998688697815,"x":0.699999988079071},{"z":0.5,"y":0.41999998688697815,"x":0.800000011920929},{"z":0.6666666865348816,"y":0.5799999833106995,"x":0.10000000149011612},{"z":0.6666666865348816,"y":0.5799999833106995,"x":0.20000000298023224},{"z":0.1666666716337204,"y":0.5799999833106995,"x":0.30000001192092896},{"z":0.1666666716337204,"y":0.5799999833106995,"x":0.4000000059604645},{"z":0.8333333134651184,"y":0.5799999833106995,"x":0.5},{"z":0.5,"y":0.5799999833106995,"x":0.6000000238418579},{"z":0.6666666865348816,"y":0.5799999833106995,"x":0.699999988079071},{"z":0.1666666716337204,"y":0.5799999833106995,"x":0.800000011920929},{"z":0.3333333432674408,"y":0.7400000095367432,"x":0.10000000149011612},{"z":1,"y":0.7400000095367432,"x":0.20000000298023224},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.30000001192092896},{"z":0.3333333432674408,"y":0.7400000095367432,"x":0.4000000059604645},{"z":1,"y":0.7400000095367432,"x":0.5},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.6000000238418579},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.699999988079071},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.800000011920929}]
The array look like: ([[1,2,3],[4,5,6]]) Every json object is a []
As I understand, json_array is a list of dictionaries
m = np.zeros((len(json_array), 3))
for i, elem in enumerate(json_array):
m[i,0] = elem['x']
m[i,1] = elem['y']
m[i,2] = elem['z']

Check if part of text is in tuple [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to check if part of text is in tuple?
For example:
my_data = ((1234L,), (23456L,), (3333L,))
And we need to find if 123 or 1234 is in tuple.
I didn't worked lot with tuples before.
In array we use:
if variable in array
But its not working for tuples like my_data
PS. 1st answer solved problem.
def findIt(data, num):
num = str(num)
return any(num in str(i) for item in data for i in item)
data = ((1234L,), (23456L,), (3333L,))
print findIt(data, 123)
Output
True

python parsing string using regex [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to parse a string from this:
CN=ERT234,OU=Computers,OU=ES1-HER,OU=ES1-Seura,OU=RES-ES1,DC=resu,DC=kt,DC=elt
To this:
ES1-HER / ES1-Seura
Any easy way to do this with regex?
>>> import re
>>> s = 'CN=ERT234,OU=Computers,OU=ES1-HER,OU=ES1-Seura,OU=RES-ES1,DC=resu,DC=kt,DC=elt'
>>> re.findall('OU=([^,]+)', s)
['Computers', 'ES1-HER', 'ES1-Seura', 'RES-ES1']
>>> re.findall('OU=([^,]+)', s)[1:3]
['ES1-HER', 'ES1-Seura']
>>> ' / '.join(re.findall('OU=([^,]+)', s)[1:3])
'ES1-HER / ES1-Seura'
Don't use str as a variable name. It shadows builtin function str.

How to count vowels in python/codewrite string? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
how to count vowels in python for example
'XaXeXUU'
should give me the answer 4
how can i calculate this?
my_string = 'XaXeXUU'
vowels = 'aeiou'
sum(ch in vowels for ch in my_string.lower())
len(my_string)-len(my_string.lower().translate(None,'aeiou'))

Categories

Resources