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

How to remove single quotes output?

I have a code, which takes a string from input_file_1 and two numbers to slice the string from input_file_2, the output strings are written in output_file and divided by space:

def task_3(input_file_1, input_file_2, output_file):
    with open(input_file_1) as i_f_1, open(input_file_2) as i_f_2, open(output_file, 'w') as o_f:
        result = []
        for line_1, line_2 in zip(i_f_1.readlines(), i_f_2.readlines()):
            start, finish = line_2.split()
            result.append(line_1[int(start):int(finish)+1])
        o_f.write(' '.join(repr(i) for i in result))

task_3('test_import_file_2_1.txt', 'test_import_file_2_2.txt', 'output_file.txt')

The problem is that output looks like this:

‘tPGRIXNp’ ‘JEflNBYRbuLkOiZqQHYNNTWPUIPNibcIpSL’
‘yDvBXxyOUwjGAemSbsuHupMmGIWpTwv’…

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

Whereas it must look like this:

tPGRIXNp JEflNBYRbuLkOiZqQHYNNTWPUIPNibcIpSL
yDvBXxyOUwjGAemSbsuHupMmGIWpTwv…

As you can see strings are attached to single quotes, which I can’t get rid off.

>Solution :

You can try removing function "repr"

o_f.write(' '.join(i for i in result))

Also you can provide an example of your input files to reproduce the problem on my computer.

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