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
asked Jul 16, 2022 at 12:25
user18726875
1 Answer 1
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
chepner
538k77 gold badges596 silver badges747 bronze badges
lang-py
init_segmentI think somewhere you are printing'/tmp/output/6 test/' + init_segment. Create a minimal reproducible example.