Home > OS >  for loop outputs functional brackets
for loop outputs functional brackets

Time:07-16

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

CodePudding user response:

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-")])
  • Related