1

At my Python code, I have the following line:

init_segment = str([init_segment for init_segment in os.listdir(job_output_root + '/' + track) if init_segment.startswith("init-")])

If I output the variable, the "[brackets]" are included in the output, why that? Currently, it looks like this:

/tmp/output/6 test/['init-a-aac_he_v2-de-mp4a.40.5_64000.m4s']

where it should look like that:

/tmp/output/6 test/init-a-aac_he_v2-de-mp4a.40.5_64000.m4s

Thanks in advance

Abhishek
4337 silver badges13 bronze badges
asked Jul 16, 2022 at 12:25
1
  • Show the line where you print init_segment I think somewhere you are printing '/tmp/output/6 test/' + init_segment. Create a minimal reproducible example. Commented Jul 16, 2022 at 12:30

1 Answer 1

2

You are getting the string representation of the list. You want a single string created from the elements of the list only; use the join method to create that string.

init_segment = ''.join([x 
 for x in os.listdir(job_output_root + '/' + track)
 if x.startswith("init-")])
answered Jul 16, 2022 at 12:30
Sign up to request clarification or add additional context in comments.

1 Comment

That seems to work way better. Thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.