Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

for loop outputs functional brackets

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']

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

where it should look like that:

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

Thanks in advance

>Solution :

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-")])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading